[PATCH] D112159: Relax assert in ExprConstant to a return None.

Jon Chesterfield via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 20 10:11:50 PDT 2021


JonChesterfield created this revision.
JonChesterfield added reviewers: gribozavr, rsmith, ABataev, dblaikie, aaron.ballman, jdoerfert.
JonChesterfield requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes a compiler assert on passing a compile time integer to atomic builtins.

Assert introduced in D61522 <https://reviews.llvm.org/D61522>
Function changed from ->bool to ->Optional in D76646 <https://reviews.llvm.org/D76646>
Most call sites for getIntegerConstantExpr check the returned optional.
Some check for isValueDependent before calling it.

This leaves some call sites with a redundant call to !isValueDependent
which could be folded into the following call to getIntegerConstantExpr.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112159

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaTemplate/atomics.cpp


Index: clang/test/SemaTemplate/atomics.cpp
===================================================================
--- clang/test/SemaTemplate/atomics.cpp
+++ clang/test/SemaTemplate/atomics.cpp
@@ -15,3 +15,13 @@
   }
   void h() { g<int>(0); }
 }
+
+// Can pass value dependent integer to atomic builtin
+template <int Order>
+void fetchAdd(int *A, int V) {
+  __atomic_fetch_add(A, V, Order);
+}
+
+void fetchAddUse(int *A, int V) {
+  fetchAdd<__ATOMIC_ACQ_REL>(A, V);
+}
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -15501,8 +15501,10 @@
 Optional<llvm::APSInt> Expr::getIntegerConstantExpr(const ASTContext &Ctx,
                                                     SourceLocation *Loc,
                                                     bool isEvaluated) const {
-  assert(!isValueDependent() &&
-         "Expression evaluator can't be called on a dependent expression.");
+  if (isValueDependent()) {
+    // Expression evaluator can't succeed on a dependent expression.
+    return None;
+  }
 
   APSInt Value;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112159.381010.patch
Type: text/x-patch
Size: 1156 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211020/1bc9d38b/attachment.bin>


More information about the cfe-commits mailing list