1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 06:32:10 +02:00

Bug 533822 - Support void* as an argument type for the GNU sync builtins

Change-Id: Idabea11af3ae00cc9bf63070b5b211e2c1242e97
This commit is contained in:
Nathan Ridge 2018-04-19 20:26:15 -04:00
parent a3211e7cf6
commit e17354be5c
2 changed files with 25 additions and 3 deletions

View file

@ -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() {

View file

@ -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);
}