[PATCH] D94438: Fis for Assertion failure on dependent expression.

Sunil Srivastava via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 11 11:25:46 PST 2021


Sunil_Srivastava created this revision.
Sunil_Srivastava added reviewers: jstenglein, erichkeane.
Sunil_Srivastava requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The check for the value passed to __buildtin_return_address needs to be guarded by check for the Dependent context, or else it runs into an assertion failure in the test case given below.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94438

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/builtin-returnaddress.c


Index: clang/test/Sema/builtin-returnaddress.c
===================================================================
--- clang/test/Sema/builtin-returnaddress.c
+++ clang/test/Sema/builtin-returnaddress.c
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -Wframe-address -verify %s
 // RUN: %clang_cc1 -fsyntax-only -Wmost -verify %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -Wframe-address -verify %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -Wmost -verify %s
 
 void* a(unsigned x) {
 return __builtin_return_address(0);
@@ -17,3 +19,14 @@
 return __builtin_frame_address(1); // expected-warning{{calling '__builtin_frame_address' with a nonzero argument is unsafe}}
 }
 
+#ifdef __cplusplus
+template<int N> void *RA()
+{
+  return __builtin_return_address(N); // expected-warning{{calling '__builtin_return_address' with a nonzero argument is unsafe}}
+}
+
+void *foo()
+{
+ return RA<2>(); // expected-note{{in instantiation of function template specialization 'RA<2>' requested here}}
+}
+#endif
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -1942,7 +1942,8 @@
     // -Wframe-address warning if non-zero passed to builtin
     // return/frame address.
     Expr::EvalResult Result;
-    if (TheCall->getArg(0)->EvaluateAsInt(Result, getASTContext()) &&
+    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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94438.315873.patch
Type: text/x-patch
Size: 1680 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210111/82dd5e77/attachment.bin>


More information about the cfe-commits mailing list