[PATCH] D146089: [Sema] Fix null pointer dereference handleAlwaysInlineAttr.
Craig Topper via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 14 13:51:49 PDT 2023
craig.topper updated this revision to Diff 505249.
craig.topper added a comment.
Add a test case
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
Index: clang/test/Sema/attr-alwaysinline.cpp
===================================================================
--- clang/test/Sema/attr-alwaysinline.cpp
+++ clang/test/Sema/attr-alwaysinline.cpp
@@ -25,3 +25,13 @@
}
[[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;
+}
+
Index: clang/lib/Sema/SemaStmtAttr.cpp
===================================================================
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -259,7 +259,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);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146089.505249.patch
Type: text/x-patch
Size: 1156 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230314/4ae7d700/attachment.bin>
More information about the cfe-commits
mailing list