[PATCH] D75768: Add a warning for builtin_return_address/frame_address with > 0 argument
Erich Keane via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 9 10:47:46 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG843a9778fcd5: Add a warning for builtin_return_address/frame_address with > 0 argument (authored by jstenglein, committed by erichkeane).
Changed prior to commit:
https://reviews.llvm.org/D75768?vs=248809&id=249161#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D75768/new/
https://reviews.llvm.org/D75768
Files:
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaChecking.cpp
clang/test/Misc/warning-wall.c
Index: clang/test/Misc/warning-wall.c
===================================================================
--- clang/test/Misc/warning-wall.c
+++ clang/test/Misc/warning-wall.c
@@ -16,6 +16,7 @@
CHECK-NEXT: -Wformat-y2k
CHECK-NEXT: -Wformat-invalid-specifier
CHECK-NEXT: -Wfor-loop-analysis
+CHECK-NEXT: -Wframe-address
CHECK-NEXT: -Wimplicit
CHECK-NEXT: -Wimplicit-function-declaration
CHECK-NEXT: -Wimplicit-int
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1853,6 +1853,17 @@
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;
}
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1780,6 +1780,11 @@
def err_illegal_union_or_anon_struct_member : Error<
"%select{anonymous struct|union}0 member %1 has a non-trivial "
"%sub{select_special_member_kind}2">;
+
+def warn_frame_address : Warning<
+ "calling '%0' with a nonzero argument is unsafe">,
+ InGroup<FrameAddress>, DefaultIgnore;
+
def warn_cxx98_compat_nontrivial_union_or_anon_struct_member : Warning<
"%select{anonymous struct|union}0 member %1 with a non-trivial "
"%sub{select_special_member_kind}2 is incompatible with C++98">,
Index: clang/include/clang/Basic/DiagnosticGroups.td
===================================================================
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -99,6 +99,7 @@
DiagGroup<"float-conversion", [FloatOverflowConversion,
FloatZeroConversion]>;
+def FrameAddress : DiagGroup<"frame-address">;
def DoublePromotion : DiagGroup<"double-promotion">;
def EnumTooLarge : DiagGroup<"enum-too-large">;
def UnsupportedNan : DiagGroup<"unsupported-nan">;
@@ -872,6 +873,7 @@
DeleteNonVirtualDtor,
Format,
ForLoopAnalysis,
+ FrameAddress,
Implicit,
InfiniteRecursion,
IntInBoolContext,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75768.249161.patch
Type: text/x-patch
Size: 2778 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200309/68fc8042/attachment.bin>
More information about the cfe-commits
mailing list