From e17354be5cbee0df09691dcff23dea4f81caed73 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Thu, 19 Apr 2018 20:26:15 -0400 Subject: [PATCH] Bug 533822 - Support void* as an argument type for the GNU sync builtins Change-Id: Idabea11af3ae00cc9bf63070b5b211e2c1242e97 --- .../core/parser/tests/ast2/AST2CPPTests.java | 9 +++++++++ .../dom/parser/GCCBuiltinSymbolProvider.java | 19 ++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java index 0f6998b7483..b66b914fdfd 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java @@ -11268,6 +11268,15 @@ public class AST2CPPTests extends AST2CPPTestBase { public void testGNUSyncBuiltins_389578() throws Exception { parseAndCheckBindings(getAboveComment(), CPP, true); } + + // int main() { + // void* p; + // __sync_bool_compare_and_swap(&p, p, p); + // __sync_fetch_and_add(&p, p, 2); + // } + public void testGNUSyncBuiltinsOnVoidPtr_533822() throws Exception { + parseAndCheckBindings(getAboveComment(), CPP, true); + } // // __int128_t and __uint128_t are available but are not keywords. // void a() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java index 89bb23609f8..6f9005f98b8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java @@ -128,10 +128,10 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider { function("void*", "__builtin_frame_address", "unsigned int"); // __sync Builtins (https://gcc.gnu.org/onlinedocs/gcc/_005f_005fsync-Builtins.html) - String[] types= {"int", "long", "long long", "unsigned int", "unsigned long", "unsigned long long"}; + String[] types= {"int", "long", "long long", "unsigned int", "unsigned long", "unsigned long long", "void*"}; for (String type : types) { // Manual does not mention volatile, however functions can be used for ptr to volatile - String typePtr= "volatile " + type + "*"; + String typePtr= type + " volatile *"; function(type, "__sync_fetch_and_add", typePtr, type, "..."); function(type, "__sync_fetch_and_sub", typePtr, type, "..."); function(type, "__sync_fetch_and_or", typePtr, type, "..."); @@ -154,7 +154,7 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider { // __atomic Builtins (https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html) for (String type : types) { // Manual does not mention volatile, however functions can be used for ptr to volatile - String typePtr= "volatile " + type + "*"; + String typePtr= type + " volatile *"; function(type, "__atomic_load_n", typePtr, "int"); function("void", "__atomic_load", typePtr, typePtr, "int"); function("void", "__atomic_store_n", typePtr, type, "int"); @@ -544,10 +544,18 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider { isConst= true; tstr= tstr.substring(6); } + if (tstr.endsWith("const")) { + isConst= true; + tstr= tstr.substring(0, tstr.length() - 5).trim(); + } if (tstr.startsWith("volatile ")) { isVolatile= true; tstr= tstr.substring(9); } + if (tstr.endsWith("volatile")) { + isVolatile= true; + tstr= tstr.substring(0, tstr.length() - 8).trim(); + } int q= 0; if (tstr.startsWith("signed ")) { q |= IBasicType.IS_SIGNED; @@ -601,6 +609,11 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider { new CPointerType(new CFunctionType(rt, IType.EMPTY_TYPE_ARRAY), 0); } else if (tstr.equals("size_t")) { t= toType("unsigned long"); + } else if (tstr.equals("void*")) { + // This can occur inside a qualifier type in which case it's not handled + // by the general '*' check above. + t= fCpp ? new CPPPointerType(new CPPBasicType(Kind.eVoid, q)) + : new CPointerType(new CBasicType(Kind.eVoid, q), 0); } else { throw new IllegalArgumentException(type); }