-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Revert "[clang][DebugInfo][NFC] Simplify CollectRecordLambdaFields" #160932
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
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
@llvm/pr-subscribers-clang-codegen @llvm/pr-subscribers-clang Author: Petr Hosek (petrhosek) ChangesReverts llvm/llvm-project#160690 Full diff: https://github.com/llvm/llvm-project/pull/160932.diff 2 Files Affected:
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 68080711c4ace..12c7d48e20d67 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -26,7 +26,6 @@
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Expr.h"
-#include "clang/AST/LambdaCapture.h"
#include "clang/AST/RecordLayout.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/VTableBuilder.h"
@@ -1904,59 +1903,46 @@ CGDebugInfo::createInlinedSubprogram(StringRef FuncName,
return SP;
}
-llvm::StringRef
-CGDebugInfo::GetLambdaCaptureName(const LambdaCapture &Capture) {
- if (Capture.capturesThis())
- return CGM.getCodeGenOpts().EmitCodeView ? "__this" : "this";
-
- assert(Capture.capturesVariable());
-
- const ValueDecl *CaptureDecl = Capture.getCapturedVar();
- assert(CaptureDecl && "Expected valid decl for captured variable.");
-
- return CaptureDecl->getName();
-}
-
void CGDebugInfo::CollectRecordLambdaFields(
const CXXRecordDecl *CXXDecl, SmallVectorImpl<llvm::Metadata *> &elements,
llvm::DIType *RecordTy) {
// For C++11 Lambdas a Field will be the same as a Capture, but the Capture
// has the name and the location of the variable so we should iterate over
// both concurrently.
+ const ASTRecordLayout &layout = CGM.getContext().getASTRecordLayout(CXXDecl);
RecordDecl::field_iterator Field = CXXDecl->field_begin();
unsigned fieldno = 0;
for (CXXRecordDecl::capture_const_iterator I = CXXDecl->captures_begin(),
E = CXXDecl->captures_end();
I != E; ++I, ++Field, ++fieldno) {
- const LambdaCapture &Capture = *I;
- const uint64_t FieldOffset =
- CGM.getContext().getASTRecordLayout(CXXDecl).getFieldOffset(fieldno);
-
- assert(!Field->isBitField() && "lambdas don't have bitfield members!");
-
- SourceLocation Loc;
- uint32_t Align = 0;
-
- if (Capture.capturesThis()) {
+ const LambdaCapture &C = *I;
+ if (C.capturesVariable()) {
+ SourceLocation Loc = C.getLocation();
+ assert(!Field->isBitField() && "lambdas don't have bitfield members!");
+ ValueDecl *V = C.getCapturedVar();
+ StringRef VName = V->getName();
+ llvm::DIFile *VUnit = getOrCreateFile(Loc);
+ auto Align = getDeclAlignIfRequired(V, CGM.getContext());
+ llvm::DIType *FieldType = createFieldType(
+ VName, Field->getType(), Loc, Field->getAccess(),
+ layout.getFieldOffset(fieldno), Align, VUnit, RecordTy, CXXDecl);
+ elements.push_back(FieldType);
+ } else if (C.capturesThis()) {
// TODO: Need to handle 'this' in some way by probably renaming the
// this of the lambda class and having a field member of 'this' or
// by using AT_object_pointer for the function and having that be
// used as 'this' for semantic references.
- Loc = Field->getLocation();
- } else {
- Loc = Capture.getLocation();
-
- const ValueDecl *CaptureDecl = Capture.getCapturedVar();
- assert(CaptureDecl && "Expected valid decl for captured variable.");
-
- Align = getDeclAlignIfRequired(CaptureDecl, CGM.getContext());
+ FieldDecl *f = *Field;
+ llvm::DIFile *VUnit = getOrCreateFile(f->getLocation());
+ QualType type = f->getType();
+ StringRef ThisName =
+ CGM.getCodeGenOpts().EmitCodeView ? "__this" : "this";
+ llvm::DIType *fieldType = createFieldType(
+ ThisName, type, f->getLocation(), f->getAccess(),
+ layout.getFieldOffset(fieldno), VUnit, RecordTy, CXXDecl);
+
+ elements.push_back(fieldType);
}
-
- llvm::DIFile *VUnit = getOrCreateFile(Loc);
-
- elements.push_back(createFieldType(
- GetLambdaCaptureName(Capture), Field->getType(), Loc,
- Field->getAccess(), FieldOffset, Align, VUnit, RecordTy, CXXDecl));
}
}
diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index 78c3eb9c5792e..f86077369a42a 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -397,7 +397,6 @@ class CGDebugInfo {
void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile *F,
SmallVectorImpl<llvm::Metadata *> &E,
llvm::DICompositeType *RecordTy);
- llvm::StringRef GetLambdaCaptureName(const LambdaCapture &Capture);
/// If the C++ class has vtable info then insert appropriate debug
/// info entry in EltTys vector.
|
@llvm/pr-subscribers-debuginfo Author: Petr Hosek (petrhosek) ChangesReverts llvm/llvm-project#160690 Full diff: https://github.com/llvm/llvm-project/pull/160932.diff 2 Files Affected:
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 68080711c4ace..12c7d48e20d67 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -26,7 +26,6 @@
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Expr.h"
-#include "clang/AST/LambdaCapture.h"
#include "clang/AST/RecordLayout.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/VTableBuilder.h"
@@ -1904,59 +1903,46 @@ CGDebugInfo::createInlinedSubprogram(StringRef FuncName,
return SP;
}
-llvm::StringRef
-CGDebugInfo::GetLambdaCaptureName(const LambdaCapture &Capture) {
- if (Capture.capturesThis())
- return CGM.getCodeGenOpts().EmitCodeView ? "__this" : "this";
-
- assert(Capture.capturesVariable());
-
- const ValueDecl *CaptureDecl = Capture.getCapturedVar();
- assert(CaptureDecl && "Expected valid decl for captured variable.");
-
- return CaptureDecl->getName();
-}
-
void CGDebugInfo::CollectRecordLambdaFields(
const CXXRecordDecl *CXXDecl, SmallVectorImpl<llvm::Metadata *> &elements,
llvm::DIType *RecordTy) {
// For C++11 Lambdas a Field will be the same as a Capture, but the Capture
// has the name and the location of the variable so we should iterate over
// both concurrently.
+ const ASTRecordLayout &layout = CGM.getContext().getASTRecordLayout(CXXDecl);
RecordDecl::field_iterator Field = CXXDecl->field_begin();
unsigned fieldno = 0;
for (CXXRecordDecl::capture_const_iterator I = CXXDecl->captures_begin(),
E = CXXDecl->captures_end();
I != E; ++I, ++Field, ++fieldno) {
- const LambdaCapture &Capture = *I;
- const uint64_t FieldOffset =
- CGM.getContext().getASTRecordLayout(CXXDecl).getFieldOffset(fieldno);
-
- assert(!Field->isBitField() && "lambdas don't have bitfield members!");
-
- SourceLocation Loc;
- uint32_t Align = 0;
-
- if (Capture.capturesThis()) {
+ const LambdaCapture &C = *I;
+ if (C.capturesVariable()) {
+ SourceLocation Loc = C.getLocation();
+ assert(!Field->isBitField() && "lambdas don't have bitfield members!");
+ ValueDecl *V = C.getCapturedVar();
+ StringRef VName = V->getName();
+ llvm::DIFile *VUnit = getOrCreateFile(Loc);
+ auto Align = getDeclAlignIfRequired(V, CGM.getContext());
+ llvm::DIType *FieldType = createFieldType(
+ VName, Field->getType(), Loc, Field->getAccess(),
+ layout.getFieldOffset(fieldno), Align, VUnit, RecordTy, CXXDecl);
+ elements.push_back(FieldType);
+ } else if (C.capturesThis()) {
// TODO: Need to handle 'this' in some way by probably renaming the
// this of the lambda class and having a field member of 'this' or
// by using AT_object_pointer for the function and having that be
// used as 'this' for semantic references.
- Loc = Field->getLocation();
- } else {
- Loc = Capture.getLocation();
-
- const ValueDecl *CaptureDecl = Capture.getCapturedVar();
- assert(CaptureDecl && "Expected valid decl for captured variable.");
-
- Align = getDeclAlignIfRequired(CaptureDecl, CGM.getContext());
+ FieldDecl *f = *Field;
+ llvm::DIFile *VUnit = getOrCreateFile(f->getLocation());
+ QualType type = f->getType();
+ StringRef ThisName =
+ CGM.getCodeGenOpts().EmitCodeView ? "__this" : "this";
+ llvm::DIType *fieldType = createFieldType(
+ ThisName, type, f->getLocation(), f->getAccess(),
+ layout.getFieldOffset(fieldno), VUnit, RecordTy, CXXDecl);
+
+ elements.push_back(fieldType);
}
-
- llvm::DIFile *VUnit = getOrCreateFile(Loc);
-
- elements.push_back(createFieldType(
- GetLambdaCaptureName(Capture), Field->getType(), Loc,
- Field->getAccess(), FieldOffset, Align, VUnit, RecordTy, CXXDecl));
}
}
diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index 78c3eb9c5792e..f86077369a42a 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -397,7 +397,6 @@ class CGDebugInfo {
void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile *F,
SmallVectorImpl<llvm::Metadata *> &E,
llvm::DICompositeType *RecordTy);
- llvm::StringRef GetLambdaCaptureName(const LambdaCapture &Capture);
/// If the C++ class has vtable info then insert appropriate debug
/// info entry in EltTys vector.
|
Prabhuk
approved these changes
Sep 26, 2025
ilovepi
approved these changes
Sep 26, 2025
mahesh-attarde
pushed a commit
to mahesh-attarde/llvm-project
that referenced
this pull request
Oct 3, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:codegen
IR generation bugs: mangling, exceptions, etc.
clang
Clang issues not falling into any other category
debuginfo
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.
Reverts #160690