]> granicus.if.org Git - clang/commitdiff
Don't emit calls to virtual [[noreturn]] functions as noreturn; overrides of a
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 5 Mar 2013 08:30:04 +0000 (08:30 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 5 Mar 2013 08:30:04 +0000 (08:30 +0000)
[[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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176476 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCall.cpp
test/CodeGenCXX/virtual-function-calls.cpp

index 4e8e724ea5a69e2176db1f216625e4085ba9fe70..6aabd64f9bd8115f795588e52d6125e4cf1ea3e4 100644 (file)
@@ -993,7 +993,10 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI,
       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);
     }
 
index 46e7b2d37f777eaf3431824b7a08e68a44a414b3..e1b380fe7369a9431b061e987b034571710a999a 100644 (file)
@@ -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
+  }
+}