Skip to content

Commit 13efd21

Browse files
authored
Merge pull request #157 from goblint/builtin_types_compatible
Ignore top level qualifiers in `__builtin_types_compatible_p`
2 parents 44f156c + cd07bb1 commit 13efd21

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/frontc/cabs2cil.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4658,7 +4658,8 @@ and doExp (asconst: bool) (* This expression is used as a constant *)
46584658
prechunk := (fun _ -> empty);
46594659
piscall := false;
46604660
let compatible =
4661-
try ignore(combineTypes CombineOther t1 t2); true
4661+
(* This built-in function ignores top level qualifiers (e.g., const, volatile). *)
4662+
try ignore(combineTypes CombineOther (removeOuterQualifierAttributes t1) (removeOuterQualifierAttributes t2)); true
46624663
with Failure _ -> false
46634664
in
46644665
if compatible then

test/small1/builtin6.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
// Extracted from the git repository.
3+
// CIL used to crash with "Error: Length of array is negative".
4+
5+
int main() {
6+
const int *a;
7+
int *ret;
8+
sizeof(*(ret)) + (sizeof(char [1 - 2*!(__builtin_types_compatible_p(__typeof__(*((ret))), __typeof__(*((a)))))]) - 1);
9+
return 0;
10+
}

test/testcil.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ sub addToGroup {
548548
addTest("testrungcc/builtin_object_size _GNUCC=1 OPTIMIZE=1");
549549
addTest("testrun/builtin4 ");
550550
addTest("test/builtin5 ");
551+
addTest("test/builtin6 ");
551552
addTest("test/sync-1 _GNUCC=1");
552553
addTest("test/sync-2 _GNUCC=1");
553554
addTest("test/sync-3 _GNUCC=1");

0 commit comments

Comments
 (0)