Issue 75856
Summary UBSan does not catch incorrect [[noreturn]] annotations if called indirectly
Labels new issue
Assignees
Reporter davidben
    UBSan catches the following invalid program:
```
#include <stdio.h>

[[noreturn]] void nope() {}

int main() {
  nope();
  printf("This should not run\n");
}
```

```
$ clang++ -fsanitize=undefined -Wno-invalid-noreturn ok.cc && ./a.out 
ok.cc:6:3: runtime error: execution reached an unreachable program point
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ok.cc:6:3 in 
```

However, it does not catch the following:
```
#include <stdio.h>

[[noreturn]] void nope() {}

void indirect_call(void (*f)()) {
  f();
}

int main() {
  indirect_call(nope);
 printf("This should not run\n");
}
```

```
$ clang++ -fsanitize=undefined -Wno-invalid-noreturn not_ok.cc && ./a.out 
This should not run
```

Poking around at the assembly output, it looks like UBSan instruments `[[noreturn]]` failures at the caller and not the callee. Instrumenting at the caller mostly works, and is nice when only the caller was instrumented. But when the function is called through a function pointer that loses the `[[noreturn]]` annotation, it loses this.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to