[PATCH] D66338: [CGP] Drop llvm.assume calls
Hal Finkel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 16 09:35:37 PDT 2019
hfinkel added a comment.
In D66338#1633249 <https://reviews.llvm.org/D66338#1633249>, @xbolva00 wrote:
> Oh, this is funny (or nasty) bug.. Never called function is now called! :)
>
> a.c
> int foo(void) __attribute__((const));
>
> int main(void) {
>
> __builtin_assume(foo() == 1);
>
> }
>
> b.c
> #include <stdio.h>
>
> int foo(void) {
>
> puts("BUM");
> return 0;
>
> }
>
> clang -O3 a.c b.c -o bum
>
> ./bum
> BUM
>
> Side note: As shown in this example, __attribute__((const)) on declarations seems like a bad idea. User may add __attribute__((const)), then in the future introduce a side effect aaaand... compiler is happy, optimizers are happy, no warnings, weird binary. Can clang-tidy catch it? @aaron.ballman @NoQ GCC folks claim this is hard to do and say __attribute__((const)) is a best effort thing - you simply shouldn't do a mistake.
This is not a bug. It's user error. We certainly might have better tooling to catch these kinds of errors, of course.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D66338/new/
https://reviews.llvm.org/D66338
More information about the llvm-commits
mailing list