[clang] cbed9a6 - [clang][Interp] Fix ignoring assumptions
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Tue May 28 03:16:50 PDT 2024
Author: Timm Bäder
Date: 2024-05-28T12:14:45+02:00
New Revision: cbed9a64491d82d6c4a3a7d0cd97cdee32ff2301
URL: https://github.com/llvm/llvm-project/commit/cbed9a64491d82d6c4a3a7d0cd97cdee32ff2301
DIFF: https://github.com/llvm/llvm-project/commit/cbed9a64491d82d6c4a3a7d0cd97cdee32ff2301.diff
LOG: [clang][Interp] Fix ignoring assumptions
Added:
Modified:
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/test/SemaCXX/cxx23-assume-disabled.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index ff92bc117f9ef..6ee7898f228de 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -687,26 +687,29 @@ bool ByteCodeStmtGen<Emitter>::visitDefaultStmt(const DefaultStmt *S) {
template <class Emitter>
bool ByteCodeStmtGen<Emitter>::visitAttributedStmt(const AttributedStmt *S) {
- for (const Attr *A : S->getAttrs()) {
- auto *AA = dyn_cast<CXXAssumeAttr>(A);
- if (!AA)
- continue;
+ if (this->Ctx.getLangOpts().CXXAssumptions &&
+ !this->Ctx.getLangOpts().MSVCCompat) {
+ for (const Attr *A : S->getAttrs()) {
+ auto *AA = dyn_cast<CXXAssumeAttr>(A);
+ if (!AA)
+ continue;
- assert(isa<NullStmt>(S->getSubStmt()));
+ assert(isa<NullStmt>(S->getSubStmt()));
- const Expr *Assumption = AA->getAssumption();
- if (Assumption->isValueDependent())
- return false;
+ const Expr *Assumption = AA->getAssumption();
+ if (Assumption->isValueDependent())
+ return false;
- if (Assumption->HasSideEffects(this->Ctx.getASTContext()))
- continue;
+ if (Assumption->HasSideEffects(this->Ctx.getASTContext()))
+ continue;
- // Evaluate assumption.
- if (!this->visitBool(Assumption))
- return false;
+ // Evaluate assumption.
+ if (!this->visitBool(Assumption))
+ return false;
- if (!this->emitAssume(Assumption))
- return false;
+ if (!this->emitAssume(Assumption))
+ return false;
+ }
}
// Ignore other attributes.
diff --git a/clang/test/SemaCXX/cxx23-assume-disabled.cpp b/clang/test/SemaCXX/cxx23-assume-disabled.cpp
index 4233a2f7f4338..674e16f5ae9b3 100644
--- a/clang/test/SemaCXX/cxx23-assume-disabled.cpp
+++ b/clang/test/SemaCXX/cxx23-assume-disabled.cpp
@@ -1,5 +1,8 @@
// RUN: %clang_cc1 -std=c++23 -x c++ %s -fno-assumptions -verify
// RUN: %clang_cc1 -std=c++23 -x c++ %s -fms-compatibility -verify
+// RUN: %clang_cc1 -std=c++23 -x c++ %s -fno-assumptions -fexperimental-new-constant-interpreter -verify
+// RUN: %clang_cc1 -std=c++23 -x c++ %s -fms-compatibility -fexperimental-new-constant-interpreter -verify
+
// expected-no-diagnostics
// We don't check assumptions at compile time if '-fno-assumptions' is passed,
More information about the cfe-commits
mailing list