mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-03-03 08:02:41 +00:00
Recommit "[Sema] Fix null pointer dereference handleAlwaysInlineAttr."
Remove use of constexpr if that failed on the build bots. Original commit message: It's possible for `getCalleeDecl()` to return a null pointer. This was encountered by a user of our downstream compiler. The case involved a DependentScopeDeclRefExpr. Since this seems to only be for a warning diagnostic, I skipped the diagnostic check if it returned null. But mabye there's a different way to fix this.
This commit is contained in:
parent
7bb14f196b
commit
e82d2e8c11
@ -233,7 +233,8 @@ static Attr *handleNoInlineAttr(Sema &S, Stmt *St, const ParsedAttr &A,
|
|||||||
|
|
||||||
for (const auto *CallExpr : CEF.getCallExprs()) {
|
for (const auto *CallExpr : CEF.getCallExprs()) {
|
||||||
const Decl *Decl = CallExpr->getCalleeDecl();
|
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)
|
S.Diag(St->getBeginLoc(), diag::warn_function_stmt_attribute_precedence)
|
||||||
<< A << (Decl->hasAttr<AlwaysInlineAttr>() ? 0 : 1);
|
<< A << (Decl->hasAttr<AlwaysInlineAttr>() ? 0 : 1);
|
||||||
}
|
}
|
||||||
@ -259,7 +260,7 @@ static Attr *handleAlwaysInlineAttr(Sema &S, Stmt *St, const ParsedAttr &A,
|
|||||||
|
|
||||||
for (const auto *CallExpr : CEF.getCallExprs()) {
|
for (const auto *CallExpr : CEF.getCallExprs()) {
|
||||||
const Decl *Decl = CallExpr->getCalleeDecl();
|
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)
|
S.Diag(St->getBeginLoc(), diag::warn_function_stmt_attribute_precedence)
|
||||||
<< A << (Decl->hasAttr<NoInlineAttr>() ? 2 : 1);
|
<< A << (Decl->hasAttr<NoInlineAttr>() ? 2 : 1);
|
||||||
}
|
}
|
||||||
|
@ -25,3 +25,16 @@ void foo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[clang::always_inline]] static int i = bar(); // expected-warning {{'always_inline' attribute only applies to functions and statements}}
|
[[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) {
|
||||||
|
[[clang::always_inline]] return foo<D-1>(x + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
[[clang::always_inline]] return bar<D-1>(x + 1);
|
||||||
|
}
|
||||||
|
@ -25,3 +25,16 @@ void foo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[clang::noinline]] static int i = bar(); // expected-warning {{'noinline' attribute only applies to functions and statements}}
|
[[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) {
|
||||||
|
[[clang::noinline]] return foo<D-1>(x + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
[[clang::noinline]] return bar<D-1>(x + 1);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user