-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][bytecode][NFC] Simplify visitDeclRef #123380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Try to reduce indentation here.
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesTry to reduce indentation here. Full diff: https://github.com/llvm/llvm-project/pull/123380.diff 1 Files Affected:
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 3ef2b0858e667b..7afae97f308ad5 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6194,60 +6194,67 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
return revisit(VD);
}
- if (D != InitializingDecl) {
- // Try to lazily visit (or emit dummy pointers for) declarations
- // we haven't seen yet.
- if (Ctx.getLangOpts().CPlusPlus) {
- if (const auto *VD = dyn_cast<VarDecl>(D)) {
- const auto typeShouldBeVisited = [&](QualType T) -> bool {
- if (T.isConstant(Ctx.getASTContext()))
- return true;
- return T->isReferenceType();
- };
+ // Avoid infinite recursion.
+ if (D == InitializingDecl)
+ return this->emitDummyPtr(D, E);
+
+ // Try to lazily visit (or emit dummy pointers for) declarations
+ // we haven't seen yet.
+ // For C.
+ if (!Ctx.getLangOpts().CPlusPlus) {
+ if (const auto *VD = dyn_cast<VarDecl>(D);
+ VD && VD->getAnyInitializer() &&
+ VD->getType().isConstant(Ctx.getASTContext()) && !VD->isWeak())
+ return revisit(VD);
+ return this->emitDummyPtr(D, E);
+ }
- // DecompositionDecls are just proxies for us.
- if (isa<DecompositionDecl>(VD))
- return revisit(VD);
-
- if ((VD->hasGlobalStorage() || VD->isStaticDataMember()) &&
- typeShouldBeVisited(VD->getType())) {
- if (const Expr *Init = VD->getAnyInitializer();
- Init && !Init->isValueDependent()) {
- // Whether or not the evaluation is successul doesn't really matter
- // here -- we will create a global variable in any case, and that
- // will have the state of initializer evaluation attached.
- APValue V;
- SmallVector<PartialDiagnosticAt> Notes;
- (void)Init->EvaluateAsInitializer(V, Ctx.getASTContext(), VD, Notes,
- true);
- return this->visitDeclRef(D, E);
- }
- return revisit(VD);
- }
+ // ... and C++.
+ const auto *VD = dyn_cast<VarDecl>(D);
+ if (!VD)
+ return this->emitDummyPtr(D, E);
- // FIXME: The evaluateValue() check here is a little ridiculous, since
- // it will ultimately call into Context::evaluateAsInitializer(). In
- // other words, we're evaluating the initializer, just to know if we can
- // evaluate the initializer.
- if (VD->isLocalVarDecl() && typeShouldBeVisited(VD->getType()) &&
- VD->getInit() && !VD->getInit()->isValueDependent()) {
+ const auto typeShouldBeVisited = [&](QualType T) -> bool {
+ if (T.isConstant(Ctx.getASTContext()))
+ return true;
+ return T->isReferenceType();
+ };
- if (VD->evaluateValue())
- return revisit(VD);
+ // DecompositionDecls are just proxies for us.
+ if (isa<DecompositionDecl>(VD))
+ return revisit(VD);
+
+ if ((VD->hasGlobalStorage() || VD->isStaticDataMember()) &&
+ typeShouldBeVisited(VD->getType())) {
+ if (const Expr *Init = VD->getAnyInitializer();
+ Init && !Init->isValueDependent()) {
+ // Whether or not the evaluation is successul doesn't really matter
+ // here -- we will create a global variable in any case, and that
+ // will have the state of initializer evaluation attached.
+ APValue V;
+ SmallVector<PartialDiagnosticAt> Notes;
+ (void)Init->EvaluateAsInitializer(V, Ctx.getASTContext(), VD, Notes,
+ true);
+ return this->visitDeclRef(D, E);
+ }
+ return revisit(VD);
+ }
+
+ // FIXME: The evaluateValue() check here is a little ridiculous, since
+ // it will ultimately call into Context::evaluateAsInitializer(). In
+ // other words, we're evaluating the initializer, just to know if we can
+ // evaluate the initializer.
+ if (VD->isLocalVarDecl() && typeShouldBeVisited(VD->getType()) &&
+ VD->getInit() && !VD->getInit()->isValueDependent()) {
+
+ if (VD->evaluateValue())
+ return revisit(VD);
- if (!D->getType()->isReferenceType())
- return this->emitDummyPtr(D, E);
+ if (!D->getType()->isReferenceType())
+ return this->emitDummyPtr(D, E);
- return this->emitInvalidDeclRef(cast<DeclRefExpr>(E),
- /*InitializerFailed=*/true, E);
- }
- }
- } else {
- if (const auto *VD = dyn_cast<VarDecl>(D);
- VD && VD->getAnyInitializer() &&
- VD->getType().isConstant(Ctx.getASTContext()) && !VD->isWeak())
- return revisit(VD);
- }
+ return this->emitInvalidDeclRef(cast<DeclRefExpr>(E),
+ /*InitializerFailed=*/true, E);
}
return this->emitDummyPtr(D, E);
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/51/builds/9302 Here is the relevant piece of the build log for the reference
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
clang
Clang issues not falling into any other category
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Try to reduce indentation here.