[PATCH] D40698: [ubsan] Diagnose noreturn functions which return

Vedant Kumar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 30 19:19:07 PST 2017


vsk planned changes to this revision.
vsk added inline comments.


================
Comment at: lib/CodeGen/CGCall.cpp:2756
                                          SourceLocation EndLoc) {
+  if (FI.isNoReturn()) {
+    // Noreturn functions don't return.
----------------
efriedma wrote:
> vsk wrote:
> > efriedma wrote:
> > > Unfortunately, this won't catch cases where the caller has a noreturn marking, but the callee doesn't.  Maybe strip the noreturn attribute from the caller, then put the sanitizer check into both the caller and callee?
> > If the caller sees a noreturn marking on the call target, inserting a 'reached-unreachable' check after the call is UB, and the optimizer throws it away. Perhaps you had a different case in mind?
> I'm thinking of the case where the caller can't see the callee, like this:
> 
> a.c:
> void a(void) __attribute((noreturn));
> void b(void) { a(); }
> 
> b.c:
> void a(void) {}
Got it. So clang would then do:

a.c:
void a(void) /* strip the noreturn attribute */;
void b(void) { a(); /* insert a reached-unreachable check here */}


https://reviews.llvm.org/D40698





More information about the cfe-commits mailing list