Skip to content

Commit

Permalink
Add definitions for integer overflow builtins from GCC
Browse files Browse the repository at this point in the history
Closes #271
  • Loading branch information
PhilippWendler authored and jonahgraham committed Feb 4, 2023
1 parent a4ba717 commit cf834dd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -474,4 +474,13 @@ public void test__attribute__aligned_bug400204() throws Exception {
parseGCC(code);
parseGPP(code);
}

// void test() {
// !__builtin_add_overflow_p(1,2,3);
// }
public void testIntegerOverflowBuiltin_bug271() throws Exception {
String code = getAboveComment();
parseGCC(code);
parseGPP(code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,20 @@ private void addGnuBuiltins() {
function("bool", "__atomic_always_lock_free", "size_t", "void*");
function("bool", "__atomic_is_lock_free", "size_t", "void*");

// Integer Overflow Builtins (https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html)
for (String op : new String[] { "add", "sub", "mul" }) {
function("bool", "__builtin_" + op + "_overflow", "", "", "void*");
function("bool", "__builtin_" + op + "_overflow_p", "", "", "");
function("bool", "__builtin_s" + op + "_overflow", "int", "int", "int*");
function("bool", "__builtin_s" + op + "l_overflow", "long int", "long int", "long int*");
function("bool", "__builtin_s" + op + "ll_overflow", "long long int", "long long int", "long long int*");
function("bool", "__builtin_u" + op + "_overflow", "unsigned int", "unsigned int", "unsigned int*");
function("bool", "__builtin_u" + op + "l_overflow", "unsigned long int", "unsigned long int",
"unsigned long int*");
function("bool", "__builtin_u" + op + "ll_overflow", "unsigned long long int", "unsigned long long int",
"unsigned long long int*");
}

ICPPExecution builtinFfs = new ExecBuiltin(ExecBuiltin.BUILTIN_FFS);
ICPPExecution builtinFfsl = new ExecBuiltin(ExecBuiltin.BUILTIN_FFSL);
ICPPExecution builtinFfsll = new ExecBuiltin(ExecBuiltin.BUILTIN_FFSLL);
Expand Down

0 comments on commit cf834dd

Please sign in to comment.