1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

Allow const-qualified arg for __atomic builtins which accept that

This commit is contained in:
Igor V. Kovalenko 2023-03-08 21:37:48 +03:00 committed by Jonah Graham
parent 3b72e60406
commit 6ea3d70456
2 changed files with 31 additions and 19 deletions

View file

@ -7719,6 +7719,14 @@ public class AST2Tests extends AST2TestBase {
parseAndCheckBindings(ScannerKind.GNU); parseAndCheckBindings(ScannerKind.GNU);
} }
// const volatile int cv_var = 0;
// int get() {
// return __atomic_load_n(&cv_var, 0);
// }
public void testAtomicLoadNOfConstVolatile() throws Exception {
parseAndCheckBindings(ScannerKind.GNU);
}
// void waldo(...); // void waldo(...);
public void testVariadicCFunction_452416() throws Exception { public void testVariadicCFunction_452416() throws Exception {
BindingAssertionHelper bh = getAssertionHelper(C); BindingAssertionHelper bh = getAssertionHelper(C);

View file

@ -160,14 +160,15 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider {
for (String type : types) { for (String type : types) {
// Manual does not mention volatile, however functions can be used for ptr to volatile // Manual does not mention volatile, however functions can be used for ptr to volatile
String typePtr = type + " volatile *"; String typePtr = type + " volatile *";
function(type, "__atomic_load_n", typePtr, "int"); String typeConstPtr = type + " const volatile *";
function("void", "__atomic_load", typePtr, typePtr, "int"); function(type, "__atomic_load_n", typeConstPtr, "int");
function("void", "__atomic_load", typeConstPtr, typePtr, "int");
function("void", "__atomic_store_n", typePtr, type, "int"); function("void", "__atomic_store_n", typePtr, type, "int");
function("void", "__atomic_store", typePtr, typePtr, "int"); function("void", "__atomic_store", typePtr, typePtr, "int");
function(type, "__atomic_exchange_n", typePtr, type, "int"); function(type, "__atomic_exchange_n", typePtr, type, "int");
function("void", "__atomic_exchange", typePtr, typePtr, typePtr, "int"); function("void", "__atomic_exchange", typePtr, typePtr, typePtr, "int");
function("bool", "__atomic_compare_exchange_n", typePtr, typePtr, type, "int", "int", "int"); function("bool", "__atomic_compare_exchange_n", typePtr, typeConstPtr, type, "int", "int", "int");
function("bool", "__atomic_compare_exchange", typePtr, typePtr, typePtr, "int", "int", "int"); function("bool", "__atomic_compare_exchange", typePtr, typeConstPtr, typePtr, "int", "int", "int");
function(type, "__atomic_add_fetch", typePtr, type, "int"); function(type, "__atomic_add_fetch", typePtr, type, "int");
function(type, "__atomic_sub_fetch", typePtr, type, "int"); function(type, "__atomic_sub_fetch", typePtr, type, "int");
function(type, "__atomic_and_fetch", typePtr, type, "int"); function(type, "__atomic_and_fetch", typePtr, type, "int");
@ -608,22 +609,25 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider {
boolean isConst = false; boolean isConst = false;
boolean isVolatile = false; boolean isVolatile = false;
if (tstr.startsWith("const ")) {
isConst = true; while (true) {
tstr = tstr.substring(6); if (tstr.startsWith("const ")) {
} isConst = true;
if (tstr.endsWith("const")) { tstr = tstr.substring(6);
isConst = true; } else if (tstr.endsWith("const")) {
tstr = tstr.substring(0, tstr.length() - 5).trim(); isConst = true;
} tstr = tstr.substring(0, tstr.length() - 5).trim();
if (tstr.startsWith("volatile ")) { } else if (tstr.startsWith("volatile ")) {
isVolatile = true; isVolatile = true;
tstr = tstr.substring(9); tstr = tstr.substring(9);
} } else if (tstr.endsWith("volatile")) {
if (tstr.endsWith("volatile")) { isVolatile = true;
isVolatile = true; tstr = tstr.substring(0, tstr.length() - 8).trim();
tstr = tstr.substring(0, tstr.length() - 8).trim(); } else {
break;
}
} }
int q = 0; int q = 0;
if (tstr.startsWith("signed ")) { if (tstr.startsWith("signed ")) {
q |= IBasicType.IS_SIGNED; q |= IBasicType.IS_SIGNED;