This revision was automatically updated to reflect the committed changes.
Closed by commit rG10297470e953: [Sema] Fix null pointer dereference 
handleAlwaysInlineAttr. (authored by craig.topper).

Changed prior to commit:
  https://reviews.llvm.org/D146089?vs=505596&id=505961#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146089/new/

https://reviews.llvm.org/D146089

Files:
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/test/Sema/attr-alwaysinline.cpp
  clang/test/Sema/attr-noinline.cpp


Index: clang/test/Sema/attr-noinline.cpp
===================================================================
--- clang/test/Sema/attr-noinline.cpp
+++ clang/test/Sema/attr-noinline.cpp
@@ -25,3 +25,22 @@
 }
 
 [[clang::noinline]] static int i = bar(); // expected-warning {{'noinline' 
attribute only applies to functions and statements}}
+
+// This used to crash the compiler.
+template<int D>
+int foo(int x) {
+    if constexpr (D > 1)
+        [[clang::noinline]] return foo<D-1>(x + 1);
+    else
+        return x;
+}
+
+// FIXME: This should warn that noinline statement attribute has higher
+// precedence than the always_inline function attribute.
+template<int D> [[clang::always_inline]]
+int bar(int x) {
+    if constexpr (D > 1)
+        [[clang::noinline]] return bar<D-1>(x + 1);
+    else
+        return x;
+}
Index: clang/test/Sema/attr-alwaysinline.cpp
===================================================================
--- clang/test/Sema/attr-alwaysinline.cpp
+++ clang/test/Sema/attr-alwaysinline.cpp
@@ -25,3 +25,22 @@
 }
 
 [[clang::always_inline]] static int i = bar(); // expected-warning 
{{'always_inline' attribute only applies to functions and statements}}
+
+// This used to crash the compiler.
+template<int D>
+int foo(int x) {
+    if constexpr (D > 1)
+        [[clang::always_inline]] return foo<D-1>(x + 1);
+    else
+        return x;
+}
+
+// FIXME: This should warn that always_inline statement attribute has higher
+// precedence than the noinline function attribute.
+template<int D> [[gnu::noinline]]
+int bar(int x) {
+    if constexpr (D > 1)
+        [[clang::always_inline]] return bar<D-1>(x + 1);
+    else
+        return x;
+}
Index: clang/lib/Sema/SemaStmtAttr.cpp
===================================================================
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -233,7 +233,8 @@
 
   for (const auto *CallExpr : CEF.getCallExprs()) {
     const Decl *Decl = CallExpr->getCalleeDecl();
-    if (Decl->hasAttr<AlwaysInlineAttr>() || Decl->hasAttr<FlattenAttr>())
+    if (Decl &&
+        (Decl->hasAttr<AlwaysInlineAttr>() || Decl->hasAttr<FlattenAttr>()))
       S.Diag(St->getBeginLoc(), diag::warn_function_stmt_attribute_precedence)
           << A << (Decl->hasAttr<AlwaysInlineAttr>() ? 0 : 1);
   }
@@ -259,7 +260,7 @@
 
   for (const auto *CallExpr : CEF.getCallExprs()) {
     const Decl *Decl = CallExpr->getCalleeDecl();
-    if (Decl->hasAttr<NoInlineAttr>() || Decl->hasAttr<FlattenAttr>())
+    if (Decl && (Decl->hasAttr<NoInlineAttr>() || 
Decl->hasAttr<FlattenAttr>()))
       S.Diag(St->getBeginLoc(), diag::warn_function_stmt_attribute_precedence)
           << A << (Decl->hasAttr<NoInlineAttr>() ? 2 : 1);
   }


Index: clang/test/Sema/attr-noinline.cpp
===================================================================
--- clang/test/Sema/attr-noinline.cpp
+++ clang/test/Sema/attr-noinline.cpp
@@ -25,3 +25,22 @@
 }
 
 [[clang::noinline]] static int i = bar(); // expected-warning {{'noinline' attribute only applies to functions and statements}}
+
+// This used to crash the compiler.
+template<int D>
+int foo(int x) {
+    if constexpr (D > 1)
+        [[clang::noinline]] return foo<D-1>(x + 1);
+    else
+        return x;
+}
+
+// FIXME: This should warn that noinline statement attribute has higher
+// precedence than the always_inline function attribute.
+template<int D> [[clang::always_inline]]
+int bar(int x) {
+    if constexpr (D > 1)
+        [[clang::noinline]] return bar<D-1>(x + 1);
+    else
+        return x;
+}
Index: clang/test/Sema/attr-alwaysinline.cpp
===================================================================
--- clang/test/Sema/attr-alwaysinline.cpp
+++ clang/test/Sema/attr-alwaysinline.cpp
@@ -25,3 +25,22 @@
 }
 
 [[clang::always_inline]] static int i = bar(); // expected-warning {{'always_inline' attribute only applies to functions and statements}}
+
+// This used to crash the compiler.
+template<int D>
+int foo(int x) {
+    if constexpr (D > 1)
+        [[clang::always_inline]] return foo<D-1>(x + 1);
+    else
+        return x;
+}
+
+// FIXME: This should warn that always_inline statement attribute has higher
+// precedence than the noinline function attribute.
+template<int D> [[gnu::noinline]]
+int bar(int x) {
+    if constexpr (D > 1)
+        [[clang::always_inline]] return bar<D-1>(x + 1);
+    else
+        return x;
+}
Index: clang/lib/Sema/SemaStmtAttr.cpp
===================================================================
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -233,7 +233,8 @@
 
   for (const auto *CallExpr : CEF.getCallExprs()) {
     const Decl *Decl = CallExpr->getCalleeDecl();
-    if (Decl->hasAttr<AlwaysInlineAttr>() || Decl->hasAttr<FlattenAttr>())
+    if (Decl &&
+        (Decl->hasAttr<AlwaysInlineAttr>() || Decl->hasAttr<FlattenAttr>()))
       S.Diag(St->getBeginLoc(), diag::warn_function_stmt_attribute_precedence)
           << A << (Decl->hasAttr<AlwaysInlineAttr>() ? 0 : 1);
   }
@@ -259,7 +260,7 @@
 
   for (const auto *CallExpr : CEF.getCallExprs()) {
     const Decl *Decl = CallExpr->getCalleeDecl();
-    if (Decl->hasAttr<NoInlineAttr>() || Decl->hasAttr<FlattenAttr>())
+    if (Decl && (Decl->hasAttr<NoInlineAttr>() || Decl->hasAttr<FlattenAttr>()))
       S.Diag(St->getBeginLoc(), diag::warn_function_stmt_attribute_precedence)
           << A << (Decl->hasAttr<NoInlineAttr>() ? 2 : 1);
   }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to