Skip to content

Commit cbed9a6

Browse files
committed
[clang][Interp] Fix ignoring assumptions
1 parent 2fc5106 commit cbed9a6

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

clang/lib/AST/Interp/ByteCodeStmtGen.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -687,26 +687,29 @@ bool ByteCodeStmtGen<Emitter>::visitDefaultStmt(const DefaultStmt *S) {
687687
template <class Emitter>
688688
bool ByteCodeStmtGen<Emitter>::visitAttributedStmt(const AttributedStmt *S) {
689689

690-
for (const Attr *A : S->getAttrs()) {
691-
auto *AA = dyn_cast<CXXAssumeAttr>(A);
692-
if (!AA)
693-
continue;
690+
if (this->Ctx.getLangOpts().CXXAssumptions &&
691+
!this->Ctx.getLangOpts().MSVCCompat) {
692+
for (const Attr *A : S->getAttrs()) {
693+
auto *AA = dyn_cast<CXXAssumeAttr>(A);
694+
if (!AA)
695+
continue;
694696

695-
assert(isa<NullStmt>(S->getSubStmt()));
697+
assert(isa<NullStmt>(S->getSubStmt()));
696698

697-
const Expr *Assumption = AA->getAssumption();
698-
if (Assumption->isValueDependent())
699-
return false;
699+
const Expr *Assumption = AA->getAssumption();
700+
if (Assumption->isValueDependent())
701+
return false;
700702

701-
if (Assumption->HasSideEffects(this->Ctx.getASTContext()))
702-
continue;
703+
if (Assumption->HasSideEffects(this->Ctx.getASTContext()))
704+
continue;
703705

704-
// Evaluate assumption.
705-
if (!this->visitBool(Assumption))
706-
return false;
706+
// Evaluate assumption.
707+
if (!this->visitBool(Assumption))
708+
return false;
707709

708-
if (!this->emitAssume(Assumption))
709-
return false;
710+
if (!this->emitAssume(Assumption))
711+
return false;
712+
}
710713
}
711714

712715
// Ignore other attributes.

clang/test/SemaCXX/cxx23-assume-disabled.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// RUN: %clang_cc1 -std=c++23 -x c++ %s -fno-assumptions -verify
22
// RUN: %clang_cc1 -std=c++23 -x c++ %s -fms-compatibility -verify
3+
// RUN: %clang_cc1 -std=c++23 -x c++ %s -fno-assumptions -fexperimental-new-constant-interpreter -verify
4+
// RUN: %clang_cc1 -std=c++23 -x c++ %s -fms-compatibility -fexperimental-new-constant-interpreter -verify
5+
36
// expected-no-diagnostics
47

58
// We don't check assumptions at compile time if '-fno-assumptions' is passed,

0 commit comments

Comments
 (0)