diff --git a/regression/ansi-c/gcc_builtin_constant_p1/main.c b/regression/ansi-c/gcc_builtin_constant_p1/main.c deleted file mode 100644 index 8ce2e0f55229..000000000000 --- a/regression/ansi-c/gcc_builtin_constant_p1/main.c +++ /dev/null @@ -1,28 +0,0 @@ -#include - -enum { E1=1 } var; - -struct whatnot -{ -} whatnot_var; - -int main() -{ - // this is gcc only - - #ifdef __GNUC__ - assert(__builtin_constant_p("some string")); - assert(__builtin_constant_p(1.0f)); - assert(__builtin_constant_p(E1)); - assert(!__builtin_constant_p(var)); - assert(!__builtin_constant_p(main)); - assert(!__builtin_constant_p(whatnot_var)); - assert(!__builtin_constant_p(&var)); - assert(__builtin_constant_p(__builtin_constant_p(var))); - - // side-effects are _not_ evaluated - int i=0; - assert(!__builtin_constant_p(i++)); - assert(i==0); - #endif -} diff --git a/regression/cbmc/gcc_builtin_constant_p1/main.c b/regression/cbmc/gcc_builtin_constant_p1/main.c new file mode 100644 index 000000000000..a0b6e5b8f737 --- /dev/null +++ b/regression/cbmc/gcc_builtin_constant_p1/main.c @@ -0,0 +1,45 @@ +#include + +enum +{ + E1 = 1 +} var; + +struct whatnot +{ +} whatnot_var; + +int main() +{ + // this is gcc only + +#ifdef __GNUC__ + assert(__builtin_constant_p("some string")); + assert(__builtin_constant_p(1.0f)); + assert(__builtin_constant_p(E1)); + assert(!__builtin_constant_p(var)); + assert(!__builtin_constant_p(main)); + assert(!__builtin_constant_p(whatnot_var)); + assert(!__builtin_constant_p(&var)); + assert(__builtin_constant_p(__builtin_constant_p(var))); + + // The following are not constant expressions in the sense of the C standard + // and GCC wouldn't deem them constant expressions either, but they are + // subject to GCC's constant folding. See also regression test ansi-c/sizeof6. + // Clang's behaviour, however, is somewhat different. See + // https://github.com/llvm/llvm-project/issues/55946 for further examples of + // where they differ. + int j; +# ifndef __clang__ + assert(__builtin_constant_p(j * 0)); + assert(__builtin_constant_p(j - j)); + assert(__builtin_constant_p(j ? 0ll : 0ll)); +# endif + assert(__builtin_constant_p(0 ? j : 0ll)); + + // side-effects are _not_ evaluated + int i = 0; + assert(!__builtin_constant_p(i++)); + assert(i == 0); +#endif +} diff --git a/regression/ansi-c/gcc_builtin_constant_p1/test.desc b/regression/cbmc/gcc_builtin_constant_p1/test.desc similarity index 63% rename from regression/ansi-c/gcc_builtin_constant_p1/test.desc rename to regression/cbmc/gcc_builtin_constant_p1/test.desc index 307a7ac801ea..659a36aac28c 100644 --- a/regression/ansi-c/gcc_builtin_constant_p1/test.desc +++ b/regression/cbmc/gcc_builtin_constant_p1/test.desc @@ -1,6 +1,7 @@ -CORE gcc-only broken-test-c++-front-end +CORE main.c +^VERIFICATION SUCCESSFUL$ ^EXIT=0$ ^SIGNAL=0$ -- diff --git a/src/ansi-c/c_typecheck_expr.cpp b/src/ansi-c/c_typecheck_expr.cpp index 7e60a27a4009..54ea3f02ec5a 100644 --- a/src/ansi-c/c_typecheck_expr.cpp +++ b/src/ansi-c/c_typecheck_expr.cpp @@ -3682,6 +3682,8 @@ exprt c_typecheck_baset::do_special_functions( { is_constant=true; } + else if(tmp1.id() == ID_string_constant) + is_constant = true; else is_constant=tmp1.is_constant();