[clang] [clang][Sema] Add noinline check for __builtin_frame_address and __builtin_return_address (PR #82966)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 4 12:15:57 PST 2024
================
@@ -2730,17 +2730,33 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
if (SemaBuiltinConstantArgRange(TheCall, 0, 0, 0xFFFF))
return ExprError();
- // -Wframe-address warning if non-zero passed to builtin
- // return/frame address.
Expr::EvalResult Result;
if (!TheCall->getArg(0)->isValueDependent() &&
- TheCall->getArg(0)->EvaluateAsInt(Result, getASTContext()) &&
- Result.Val.getInt() != 0)
- Diag(TheCall->getBeginLoc(), diag::warn_frame_address)
- << ((BuiltinID == Builtin::BI__builtin_return_address)
- ? "__builtin_return_address"
- : "__builtin_frame_address")
- << TheCall->getSourceRange();
+ TheCall->getArg(0)->EvaluateAsInt(Result, getASTContext())) {
+ const char *BuiltinName =
+ (BuiltinID == Builtin::BI__builtin_return_address)
+ ? "__builtin_return_address"
+ : "__builtin_frame_address";
+
+ // -Wframe-address warning if non-zero passed to builtin
+ // return/frame address.
+ if (Result.Val.getInt() != 0) {
+ Diag(TheCall->getBeginLoc(), diag::warn_frame_address)
+ << BuiltinName << TheCall->getSourceRange();
+ }
+
+ // -Wframe-address warning if enclosing function is not marked noinline.
+ if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurContext)) {
+ if (!FD->hasAttr<NoInlineAttr>() && !FD->isMain()) {
----------------
AaronBallman wrote:
```suggestion
if (const auto *FD = dyn_cast<FunctionDecl>(CurContext);
FD && !FD->hasAttr<NoInlineAttr>() && !FD->isMain()) {
```
https://github.com/llvm/llvm-project/pull/82966
More information about the cfe-commits
mailing list