|
26 | 26 | #include "clang/AST/DeclObjC.h"
|
27 | 27 | #include "clang/AST/DeclTemplate.h"
|
28 | 28 | #include "clang/AST/Expr.h"
|
29 |
| -#include "clang/AST/LambdaCapture.h" |
30 | 29 | #include "clang/AST/RecordLayout.h"
|
31 | 30 | #include "clang/AST/RecursiveASTVisitor.h"
|
32 | 31 | #include "clang/AST/VTableBuilder.h"
|
@@ -1904,59 +1903,46 @@ CGDebugInfo::createInlinedSubprogram(StringRef FuncName,
|
1904 | 1903 | return SP;
|
1905 | 1904 | }
|
1906 | 1905 |
|
1907 |
| -llvm::StringRef |
1908 |
| -CGDebugInfo::GetLambdaCaptureName(const LambdaCapture &Capture) { |
1909 |
| - if (Capture.capturesThis()) |
1910 |
| - return CGM.getCodeGenOpts().EmitCodeView ? "__this" : "this"; |
1911 |
| - |
1912 |
| - assert(Capture.capturesVariable()); |
1913 |
| - |
1914 |
| - const ValueDecl *CaptureDecl = Capture.getCapturedVar(); |
1915 |
| - assert(CaptureDecl && "Expected valid decl for captured variable."); |
1916 |
| - |
1917 |
| - return CaptureDecl->getName(); |
1918 |
| -} |
1919 |
| - |
1920 | 1906 | void CGDebugInfo::CollectRecordLambdaFields(
|
1921 | 1907 | const CXXRecordDecl *CXXDecl, SmallVectorImpl<llvm::Metadata *> &elements,
|
1922 | 1908 | llvm::DIType *RecordTy) {
|
1923 | 1909 | // For C++11 Lambdas a Field will be the same as a Capture, but the Capture
|
1924 | 1910 | // has the name and the location of the variable so we should iterate over
|
1925 | 1911 | // both concurrently.
|
| 1912 | + const ASTRecordLayout &layout = CGM.getContext().getASTRecordLayout(CXXDecl); |
1926 | 1913 | RecordDecl::field_iterator Field = CXXDecl->field_begin();
|
1927 | 1914 | unsigned fieldno = 0;
|
1928 | 1915 | for (CXXRecordDecl::capture_const_iterator I = CXXDecl->captures_begin(),
|
1929 | 1916 | E = CXXDecl->captures_end();
|
1930 | 1917 | I != E; ++I, ++Field, ++fieldno) {
|
1931 |
| - const LambdaCapture &Capture = *I; |
1932 |
| - const uint64_t FieldOffset = |
1933 |
| - CGM.getContext().getASTRecordLayout(CXXDecl).getFieldOffset(fieldno); |
1934 |
| - |
1935 |
| - assert(!Field->isBitField() && "lambdas don't have bitfield members!"); |
1936 |
| - |
1937 |
| - SourceLocation Loc; |
1938 |
| - uint32_t Align = 0; |
1939 |
| - |
1940 |
| - if (Capture.capturesThis()) { |
| 1918 | + const LambdaCapture &C = *I; |
| 1919 | + if (C.capturesVariable()) { |
| 1920 | + SourceLocation Loc = C.getLocation(); |
| 1921 | + assert(!Field->isBitField() && "lambdas don't have bitfield members!"); |
| 1922 | + ValueDecl *V = C.getCapturedVar(); |
| 1923 | + StringRef VName = V->getName(); |
| 1924 | + llvm::DIFile *VUnit = getOrCreateFile(Loc); |
| 1925 | + auto Align = getDeclAlignIfRequired(V, CGM.getContext()); |
| 1926 | + llvm::DIType *FieldType = createFieldType( |
| 1927 | + VName, Field->getType(), Loc, Field->getAccess(), |
| 1928 | + layout.getFieldOffset(fieldno), Align, VUnit, RecordTy, CXXDecl); |
| 1929 | + elements.push_back(FieldType); |
| 1930 | + } else if (C.capturesThis()) { |
1941 | 1931 | // TODO: Need to handle 'this' in some way by probably renaming the
|
1942 | 1932 | // this of the lambda class and having a field member of 'this' or
|
1943 | 1933 | // by using AT_object_pointer for the function and having that be
|
1944 | 1934 | // used as 'this' for semantic references.
|
1945 |
| - Loc = Field->getLocation(); |
1946 |
| - } else { |
1947 |
| - Loc = Capture.getLocation(); |
1948 |
| - |
1949 |
| - const ValueDecl *CaptureDecl = Capture.getCapturedVar(); |
1950 |
| - assert(CaptureDecl && "Expected valid decl for captured variable."); |
1951 |
| - |
1952 |
| - Align = getDeclAlignIfRequired(CaptureDecl, CGM.getContext()); |
| 1935 | + FieldDecl *f = *Field; |
| 1936 | + llvm::DIFile *VUnit = getOrCreateFile(f->getLocation()); |
| 1937 | + QualType type = f->getType(); |
| 1938 | + StringRef ThisName = |
| 1939 | + CGM.getCodeGenOpts().EmitCodeView ? "__this" : "this"; |
| 1940 | + llvm::DIType *fieldType = createFieldType( |
| 1941 | + ThisName, type, f->getLocation(), f->getAccess(), |
| 1942 | + layout.getFieldOffset(fieldno), VUnit, RecordTy, CXXDecl); |
| 1943 | + |
| 1944 | + elements.push_back(fieldType); |
1953 | 1945 | }
|
1954 |
| - |
1955 |
| - llvm::DIFile *VUnit = getOrCreateFile(Loc); |
1956 |
| - |
1957 |
| - elements.push_back(createFieldType( |
1958 |
| - GetLambdaCaptureName(Capture), Field->getType(), Loc, |
1959 |
| - Field->getAccess(), FieldOffset, Align, VUnit, RecordTy, CXXDecl)); |
1960 | 1946 | }
|
1961 | 1947 | }
|
1962 | 1948 |
|
|
0 commit comments