Skip to content

Commit 59d79fd

Browse files
committed
Revert "[clang][bytecode] Save Constexpr bit in Function (llvm#142793)"
This reverts commit 478bdd8.
1 parent 9db7502 commit 59d79fd

File tree

4 files changed

+12
-17
lines changed

4 files changed

+12
-17
lines changed

clang/lib/AST/ByteCode/Context.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ bool Context::isPotentialConstantExpr(State &Parent, const FunctionDecl *FD) {
4949
if (!Run(Parent, Func))
5050
return false;
5151

52-
return Func->isValid();
52+
return Func->isConstexpr();
5353
}
5454

5555
bool Context::evaluateAsRValue(State &Parent, const Expr *E, APValue &Result) {

clang/lib/AST/ByteCode/Function.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ Function::Function(Program &P, FunctionDeclTy Source, unsigned ArgSize,
2727
if (const auto *F = dyn_cast<const FunctionDecl *>(Source)) {
2828
Variadic = F->isVariadic();
2929
Immediate = F->isImmediateFunction();
30-
Constexpr = F->isConstexpr() || F->hasAttr<MSConstexprAttr>();
3130
if (const auto *CD = dyn_cast<CXXConstructorDecl>(F)) {
3231
Virtual = CD->isVirtual();
3332
Kind = FunctionKind::Ctor;
@@ -49,7 +48,6 @@ Function::Function(Program &P, FunctionDeclTy Source, unsigned ArgSize,
4948
Variadic = false;
5049
Virtual = false;
5150
Immediate = false;
52-
Constexpr = false;
5351
}
5452
}
5553

clang/lib/AST/ByteCode/Function.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,12 @@ class Function final {
150150
/// Returns the source information at a given PC.
151151
SourceInfo getSource(CodePtr PC) const;
152152

153-
/// Checks if the function is valid to call.
154-
bool isValid() const { return IsValid || isLambdaStaticInvoker(); }
153+
/// Checks if the function is valid to call in constexpr.
154+
bool isConstexpr() const { return IsValid || isLambdaStaticInvoker(); }
155155

156156
/// Checks if the function is virtual.
157157
bool isVirtual() const { return Virtual; };
158158
bool isImmediate() const { return Immediate; }
159-
bool isConstexpr() const { return Constexpr; }
160159

161160
/// Checks if the function is a constructor.
162161
bool isConstructor() const { return Kind == FunctionKind::Ctor; }
@@ -304,8 +303,6 @@ class Function final {
304303
unsigned Virtual : 1;
305304
LLVM_PREFERRED_TYPE(bool)
306305
unsigned Immediate : 1;
307-
LLVM_PREFERRED_TYPE(bool)
308-
unsigned Constexpr : 1;
309306

310307
public:
311308
/// Dumps the disassembled bytecode to \c llvm::errs().

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -857,22 +857,23 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
857857
return false;
858858
}
859859

860+
// Bail out if the function declaration itself is invalid. We will
861+
// have produced a relevant diagnostic while parsing it, so just
862+
// note the problematic sub-expression.
863+
if (F->getDecl()->isInvalidDecl())
864+
return Invalid(S, OpPC);
865+
860866
if (S.checkingPotentialConstantExpression() && S.Current->getDepth() != 0)
861867
return false;
862868

863-
if (F->isValid() && F->hasBody() && F->isConstexpr())
869+
if (F->isConstexpr() && F->hasBody() &&
870+
(F->getDecl()->isConstexpr() || F->getDecl()->hasAttr<MSConstexprAttr>()))
864871
return true;
865872

866873
// Implicitly constexpr.
867874
if (F->isLambdaStaticInvoker())
868875
return true;
869876

870-
// Bail out if the function declaration itself is invalid. We will
871-
// have produced a relevant diagnostic while parsing it, so just
872-
// note the problematic sub-expression.
873-
if (F->getDecl()->isInvalidDecl())
874-
return Invalid(S, OpPC);
875-
876877
// Diagnose failed assertions specially.
877878
if (S.Current->getLocation(OpPC).isMacroID() &&
878879
F->getDecl()->getIdentifier()) {
@@ -922,8 +923,7 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
922923
// for a constant expression. It might be defined at the point we're
923924
// actually calling it.
924925
bool IsExtern = DiagDecl->getStorageClass() == SC_Extern;
925-
bool IsDefined = F->isDefined();
926-
if (!IsDefined && !IsExtern && DiagDecl->isConstexpr() &&
926+
if (!DiagDecl->isDefined() && !IsExtern && DiagDecl->isConstexpr() &&
927927
S.checkingPotentialConstantExpression())
928928
return false;
929929

0 commit comments

Comments
 (0)