Skip to content

Commit

Permalink
Allow const-qualified arg for __atomic builtins which accept that
Browse files Browse the repository at this point in the history
  • Loading branch information
i-garrison committed Mar 8, 2023
1 parent 6776f6a commit b974443
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7719,6 +7719,14 @@ public void testAtomicBuiltin_bug456131() throws Exception {
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(...);
public void testVariadicCFunction_452416() throws Exception {
BindingAssertionHelper bh = getAssertionHelper(C);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,15 @@ private void addGnuBuiltins() {
for (String type : types) {
// Manual does not mention volatile, however functions can be used for ptr to volatile
String typePtr = type + " volatile *";
function(type, "__atomic_load_n", typePtr, "int");
function("void", "__atomic_load", typePtr, typePtr, "int");
String typeConstPtr = type + " const volatile *";
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", typePtr, typePtr, "int");
function(type, "__atomic_exchange_n", typePtr, type, "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", typePtr, typePtr, typePtr, "int", "int", "int");
function("bool", "__atomic_compare_exchange_n", typePtr, typeConstPtr, type, "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_sub_fetch", typePtr, type, "int");
function(type, "__atomic_and_fetch", typePtr, type, "int");
Expand Down Expand Up @@ -608,22 +609,25 @@ private IType createType(final String type) {

boolean isConst = false;
boolean isVolatile = false;
if (tstr.startsWith("const ")) {
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();

while (true) {
if (tstr.startsWith("const ")) {
isConst = true;
tstr = tstr.substring(6);
} else if (tstr.endsWith("const")) {
isConst = true;
tstr = tstr.substring(0, tstr.length() - 5).trim();
} else if (tstr.startsWith("volatile ")) {
isVolatile = true;
tstr = tstr.substring(9);
} else if (tstr.endsWith("volatile")) {
isVolatile = true;
tstr = tstr.substring(0, tstr.length() - 8).trim();
} else {
break;
}
}

int q = 0;
if (tstr.startsWith("signed ")) {
q |= IBasicType.IS_SIGNED;
Expand Down

0 comments on commit b974443

Please sign in to comment.