[llvm-bugs] [Bug 49337] New: accept-invalid: __builtin_types_compatible_p pollutes the environment of tag type checking
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Feb 23 20:37:18 PST 2021
https://bugs.llvm.org/show_bug.cgi?id=49337
Bug ID: 49337
Summary: accept-invalid: __builtin_types_compatible_p pollutes
the environment of tag type checking
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: zhan3299 at purdue.edu
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
neeilans at live.com, richard-llvm at metafoo.co.uk
I am not sure how to accurately describe the problem. In short,
Following code is obviously invalid, as the use of 'X' with tag type does not
match previous declaration (https://godbolt.org/z/qad8vz).
$ cat case1.c
struct X {
union X {
int b;
long c;
} d;
} a;
int main() { return 0; }
However, when we put this erroneous declaration into a
__builtin_types_compatible_p function, clang accepts it
(https://godbolt.org/z/TrxTzs). Note that it is rejected by GCC
(https://godbolt.org/z/rWde88).
$ cat case2.c
int main() {
int a = __builtin_types_compatible_p(int, struct X {
union X {
int b;
long c;
} d;
});
return a;
}
Even worse, this invalid __builtin_types_compatible_p may additionally affects
other statements (https://godbolt.org/z/avxvzj), which, at least, gives the
wrong error reports.
$ cat case3.c
int main() {
int a = __builtin_types_compatible_p(int, struct X {
union X {
int b;
long c;
} d;
});
enum X { A, B } h;
h = A;
return a;
}
$ clang case3.c
#1 with x86-64 clang (trunk)
case3.c:10:9: error: use of undeclared identifier 'A'
h = A;
^
1 error generated.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210224/ad489327/attachment.html>
More information about the llvm-bugs
mailing list