From e9060b812aabc6de26287903e7ca6e46c95d3b18 Mon Sep 17 00:00:00 2001 From: Karoliine Holter Date: Mon, 2 Oct 2023 15:45:05 +0300 Subject: [PATCH 1/2] Add test case extracted from the git repository --- test/small1/builtin6.c | 10 ++++++++++ test/testcil.pl | 1 + 2 files changed, 11 insertions(+) create mode 100644 test/small1/builtin6.c diff --git a/test/small1/builtin6.c b/test/small1/builtin6.c new file mode 100644 index 000000000..56e4388d8 --- /dev/null +++ b/test/small1/builtin6.c @@ -0,0 +1,10 @@ + +// Extracted from the git repository. +// CIL used to crash with "Error: Length of array is negative". + +int main() { + const int *a; + int *ret; + sizeof(*(ret)) + (sizeof(char [1 - 2*!(__builtin_types_compatible_p(__typeof__(*((ret))), __typeof__(*((a)))))]) - 1); + return 0; +} \ No newline at end of file diff --git a/test/testcil.pl b/test/testcil.pl index 3f495f0ed..a33e9af7a 100644 --- a/test/testcil.pl +++ b/test/testcil.pl @@ -548,6 +548,7 @@ sub addToGroup { addTest("testrungcc/builtin_object_size _GNUCC=1 OPTIMIZE=1"); addTest("testrun/builtin4 "); addTest("test/builtin5 "); +addTest("test/builtin6 "); addTest("test/sync-1 _GNUCC=1"); addTest("test/sync-2 _GNUCC=1"); addTest("test/sync-3 _GNUCC=1"); From cd07bb1d02f822b39a8a86d6fef285021247a342 Mon Sep 17 00:00:00 2001 From: Karoliine Holter Date: Mon, 2 Oct 2023 15:45:56 +0300 Subject: [PATCH 2/2] Ignore top level qualifiers in __builtin_types_compatible_p --- src/frontc/cabs2cil.ml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/frontc/cabs2cil.ml b/src/frontc/cabs2cil.ml index 616669caa..b0839d066 100644 --- a/src/frontc/cabs2cil.ml +++ b/src/frontc/cabs2cil.ml @@ -4658,7 +4658,8 @@ and doExp (asconst: bool) (* This expression is used as a constant *) prechunk := (fun _ -> empty); piscall := false; let compatible = - try ignore(combineTypes CombineOther t1 t2); true + (* This built-in function ignores top level qualifiers (e.g., const, volatile). *) + try ignore(combineTypes CombineOther (removeOuterQualifierAttributes t1) (removeOuterQualifierAttributes t2)); true with Failure _ -> false in if compatible then