Issue 143284
Summary unnecessary constraint enforcement in arguments to __builtin_types_compatible_p
Labels new issue
Assignees
Reporter alejandro-colomar
    Here's a small reproducer:

```c
alx@devuan:~/tmp$ cat cnt.c 
#include <stdlib.h>
#include <assert.h>


#define must_be(e) \
( \
        0 * (int) sizeof( \
                struct { \
                        static_assert(e, ""); \
                        int ISO_C_forbids_a_struct_with_no_members_;  \
                } \
        ) \
)

#define is_same_type(a, b) \
( \
        __builtin_types_compatible_p(a, b) \
)

#define is_same_typeof(a, b) \
( \
        is_same_type(typeof(a), typeof(b)) \
)

#define is_array(a) \
( \
        !is_same_typeof(a, &(a)[0]) \
)


int
main(void)
{
	return must_be(is_array(((int []) {rand(), rand()})));
}
```
```c
alx@devuan:~/tmp$ gcc -Wall -Wextra -S cnt.c 
alx@devuan:~/tmp$
```
```c
alx@devuan:~/tmp$ clang -Wall -Wextra -S cnt.c 
cnt.c:34:37: error: initializer element is not a compile-time constant
   34 |         return must_be(is_array(((int []) {rand(), rand()})));
      | ^~~~~~
cnt.c:27:25: note: expanded from macro 'is_array'
   27 | !is_same_typeof(a, &(a)[0])                                   \
      | ^
cnt.c:22:29: note: expanded from macro 'is_same_typeof'
   22 |         is_same_type(typeof(a), typeof(b)) \
      |                             ^
cnt.c:17:38: note: expanded from macro 'is_same_type'
   17 | __builtin_types_compatible_p(a, b)                            \
      | ^
cnt.c:9:39: note: expanded from macro 'must_be'
    9 |                         static_assert(e, ""); \
      |                                       ^
1 error generated.
```

Please include the following in an eventual fix:

```
Reported-by: "Basil L. Contovounesios" <ba...@contovou.net>
Reported-by: Alejandro Colomar <a...@kernel.org>
```

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to