r176476 - Don't emit calls to virtual [[noreturn]] functions as noreturn; overrides of a

Richard Smith richard-llvm at metafoo.co.uk
Tue Mar 5 00:30:04 PST 2013


Author: rsmith
Date: Tue Mar  5 02:30:04 2013
New Revision: 176476

URL: http://llvm.org/viewvc/llvm-project?rev=176476&view=rev
Log:
Don't emit calls to virtual [[noreturn]] functions as noreturn; overrides of a
[[noreturn]] function are not required to also be [[noreturn]]. We still emit
calls to virtual __attribute__((noreturn)) functions as noreturn; unlike GCC,
we do require overriders to also be noreturn for that attribute.

Modified:
    cfe/trunk/lib/CodeGen/CGCall.cpp
    cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=176476&r1=176475&r2=176476&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Tue Mar  5 02:30:04 2013
@@ -993,7 +993,10 @@ void CodeGenModule::ConstructAttributeLi
       const FunctionProtoType *FPT = Fn->getType()->getAs<FunctionProtoType>();
       if (FPT && FPT->isNothrow(getContext()))
         FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
-      if (Fn->isNoReturn())
+      // Don't use [[noreturn]] or _Noreturn for a call to a virtual function.
+      // These attributes are not inherited by overloads.
+      const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(Fn);
+      if (Fn->isNoReturn() && !(AttrOnCallSite && MD && MD->isVirtual()))
         FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
     }
 

Modified: cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp?rev=176476&r1=176475&r2=176476&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp Tue Mar  5 02:30:04 2013
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -std=c++11 -emit-llvm -o - | FileCheck %s
 
 // PR5021
 namespace PR5021 {
@@ -36,3 +36,16 @@ namespace Test1 {
     b->f();
   }
 }
+
+namespace VirtualNoreturn {
+  struct A {
+    [[noreturn]] virtual void f();
+  };
+
+  // CHECK: @_ZN15VirtualNoreturn1f
+  void f(A *p) {
+    p->f();
+    // CHECK: call void %{{[^#]*$}}
+    // CHECK-NOT: unreachable
+  }
+}





More information about the cfe-commits mailing list