diff options
author | Jeremy Stenglein <jstenglein@gmail.com> | 2020-03-09 10:17:15 -0700 |
---|---|---|
committer | Erich Keane <erich.keane@intel.com> | 2020-03-09 10:43:09 -0700 |
commit | 843a9778fcd5ef93804fc22de04af9ab8c8b20a9 (patch) | |
tree | 4b3f6ebab94fa92f835d992236b1bd2471decd6a /clang/lib | |
parent | eb682b80274d5486d062e3f53040969f592277e4 (diff) | |
download | llvm-843a9778fcd5ef93804fc22de04af9ab8c8b20a9.zip llvm-843a9778fcd5ef93804fc22de04af9ab8c8b20a9.tar.gz llvm-843a9778fcd5ef93804fc22de04af9ab8c8b20a9.tar.bz2 |
Add a warning for builtin_return_address/frame_address with > 0 argument
Clang is missing a warning for
builtin_return_address/builtin_frame_address called with > 0 argument.
Gcc provides a warning for this via -Wframe-address:
https://gcc.gnu.org/onlinedocs/gcc/Return-Address.html
As calling these functions with argument > 0 has caused several crashes
for us, we would like to have the same warning as gcc here. This diff
adds the warning and makes it part of -Wmost.
Differential Revision: https://reviews.llvm.org/D75768
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 106e90f..2e73fca 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -1853,6 +1853,17 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, case Builtin::BI__builtin_return_address: 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)->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(); break; } |