[PATCH] D23168: emit_DW_AT_noreturn flag

Victor via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 17 01:38:26 PDT 2016


vleschuk updated this revision to Diff 68321.
vleschuk added a comment.

More context in text.


https://reviews.llvm.org/D23168

Files:
  lib/AST/Decl.cpp
  lib/CodeGen/CGDebugInfo.cpp
  test/Frontend/dinoreturn.c
  test/Frontend/dinoreturn.cpp
  test/Frontend/dinoreturn.m

Index: test/Frontend/dinoreturn.m
===================================================================
--- /dev/null
+++ test/Frontend/dinoreturn.m
@@ -0,0 +1,5 @@
+// RUN: %clang %s -c -emit-llvm -S -g -o - | FileCheck %s
+// CHECK: !DISubprogram({{.*}}name: "f"{{.*}}flags:{{.*DIFlagNoReturn}}
+__attribute__ ((noreturn)) void f() {
+  exit(0);
+}
Index: test/Frontend/dinoreturn.cpp
===================================================================
--- /dev/null
+++ test/Frontend/dinoreturn.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang %s -c -std=c++11 -x c++ -emit-llvm -S -g -o - | FileCheck %s
+// CHECK: !DISubprogram({{.*}}name: "f"{{.*}}flags:{{.*DIFlagNoReturn}}
+[[ noreturn ]] void f() {
+  throw 1;
+}
Index: test/Frontend/dinoreturn.c
===================================================================
--- /dev/null
+++ test/Frontend/dinoreturn.c
@@ -0,0 +1,6 @@
+// RUN: %clang %s -c -std=c11 -emit-llvm -S -g -o - | FileCheck %s
+// CHECK: !DISubprogram({{.*}}name: "f"{{.*}}flags:{{.*DIFlagNoReturn}}
+#include <stdlib.h>
+_Noreturn void f() {
+  exit(0);
+}
Index: lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -2641,6 +2641,9 @@
       llvm::DIScope *Mod = getParentModuleOrNull(RDecl);
       FDContext = getContextDescriptor(RDecl, Mod ? Mod : TheCU);
     }
+    // Check if it is a noreturn-marked function
+    if (FD->isNoReturn())
+      Flags |= llvm::DINode::FlagNoReturn;
     // Collect template parameters.
     TParamsArray = CollectFunctionTemplateParams(FD, Unit);
   }
Index: lib/AST/Decl.cpp
===================================================================
--- lib/AST/Decl.cpp
+++ lib/AST/Decl.cpp
@@ -2657,9 +2657,13 @@
 }
 
 bool FunctionDecl::isNoReturn() const {
-  return hasAttr<NoReturnAttr>() || hasAttr<CXX11NoReturnAttr>() ||
-         hasAttr<C11NoReturnAttr>() ||
-         getType()->getAs<FunctionType>()->getNoReturnAttr();
+  bool HasNoReturnAttr = hasAttr<NoReturnAttr>() || hasAttr<CXX11NoReturnAttr>()
+                         || hasAttr<C11NoReturnAttr>();
+  const auto *FuncType = getType()->getAs<FunctionType>();
+  bool TypeHasNoReturnAttr = false;
+  if (FuncType)
+    TypeHasNoReturnAttr = FuncType->getNoReturnAttr();
+  return HasNoReturnAttr || TypeHasNoReturnAttr;
 }
 
 void


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23168.68321.patch
Type: text/x-patch
Size: 2360 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160817/8d10117c/attachment.bin>


More information about the cfe-commits mailing list