Skip to content

Commit 4cf607f

Browse files
committed
[clang][Interp] Fix visiting non-FieldDecl MemberExprs
Ignore the base and visit the Member decl like a regular DeclRefExpr.
1 parent 00c5474 commit 4cf607f

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,9 @@ bool ByteCodeExprGen<Emitter>::VisitMemberExpr(const MemberExpr *E) {
14941494
return false;
14951495
}
14961496

1497+
if (!isa<FieldDecl>(Member))
1498+
return this->discard(Base) && this->visitDeclRef(Member, E);
1499+
14971500
if (Initializing) {
14981501
if (!this->delegate(Base))
14991502
return false;
@@ -1503,19 +1506,16 @@ bool ByteCodeExprGen<Emitter>::VisitMemberExpr(const MemberExpr *E) {
15031506
}
15041507

15051508
// Base above gives us a pointer on the stack.
1506-
if (const auto *FD = dyn_cast<FieldDecl>(Member)) {
1507-
const RecordDecl *RD = FD->getParent();
1508-
const Record *R = getRecord(RD);
1509-
if (!R)
1510-
return false;
1511-
const Record::Field *F = R->getField(FD);
1512-
// Leave a pointer to the field on the stack.
1513-
if (F->Decl->getType()->isReferenceType())
1514-
return this->emitGetFieldPop(PT_Ptr, F->Offset, E) && maybeLoadValue();
1515-
return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
1516-
}
1517-
1518-
return false;
1509+
const auto *FD = cast<FieldDecl>(Member);
1510+
const RecordDecl *RD = FD->getParent();
1511+
const Record *R = getRecord(RD);
1512+
if (!R)
1513+
return false;
1514+
const Record::Field *F = R->getField(FD);
1515+
// Leave a pointer to the field on the stack.
1516+
if (F->Decl->getType()->isReferenceType())
1517+
return this->emitGetFieldPop(PT_Ptr, F->Offset, E) && maybeLoadValue();
1518+
return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
15191519
}
15201520

15211521
template <class Emitter>

clang/test/SemaCXX/ms-const-member-expr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 %s -std=c++11 -fms-compatibility -fsyntax-only -verify
2+
// RUN: %clang_cc1 %s -std=c++11 -fms-compatibility -fsyntax-only -verify -fexperimental-new-constant-interpreter
23

34
struct S {
45
enum { E = 1 };

0 commit comments

Comments
 (0)