-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[lldb][DWARFASTParserClang] Adjust language type for conflicting Objective-C++ forward declarations #130768
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
Open
Michael137
wants to merge
1
commit into
llvm:main
Choose a base branch
from
Michael137:lldb/objcpp-forward-decls
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+108
−0
Open
[lldb][DWARFASTParserClang] Adjust language type for conflicting Objective-C++ forward declarations #130768
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -351,6 +351,41 @@ static void PrepareContextToReceiveMembers(TypeSystemClang &ast, | |
} | ||
} | ||
|
||
/// Returns \c true if a forward declaration in C or C++ is actually an | ||
/// Objective-C++ forward declaration. Otherwise, or on error, returns | ||
/// \c false. | ||
static bool IsCppForwardDeclObjC(SymbolFileDWARF &dwarf, | ||
const ParsedDWARFTypeAttributes &attrs) { | ||
assert(attrs.is_forward_declaration); | ||
|
||
if (Language::LanguageIsObjC(attrs.class_language)) | ||
return false; | ||
|
||
TypeQuery query(attrs.name); | ||
TypeResults results; | ||
|
||
if (SymbolFileDWARFDebugMap *debug_map_symfile = dwarf.GetDebugMapSymfile()) | ||
debug_map_symfile->FindTypes(query, results); | ||
else | ||
dwarf.FindTypes(query, results); | ||
|
||
// Check that all types we found are Objective-C++ types. | ||
// Otherwise we're dealing with an actual ODR violation and | ||
// we can't say for sure what language this forward declaration | ||
// referred to. | ||
bool all_objc_types = true; | ||
results.GetTypeMap().ForEach([&](const lldb::TypeSP &t) -> bool { | ||
assert(t); | ||
|
||
all_objc_types &= Language::LanguageIsObjC( | ||
t->GetForwardCompilerType().GetMinimumLanguage()); | ||
|
||
return true; | ||
}); | ||
|
||
return all_objc_types; | ||
} | ||
|
||
ParsedDWARFTypeAttributes::ParsedDWARFTypeAttributes(const DWARFDIE &die) { | ||
DWARFAttributes attributes = die.GetAttributes(); | ||
for (size_t i = 0; i < attributes.Size(); ++i) { | ||
|
@@ -1810,6 +1845,9 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc, | |
} | ||
|
||
if (attrs.is_forward_declaration) { | ||
if (IsCppForwardDeclObjC(*dwarf, attrs)) | ||
attrs.class_language = eLanguageTypeObjC_plus_plus; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does that mean we do full global search for every C++ fwddecl we encounter? |
||
|
||
// See if the type comes from a Clang module and if so, track down | ||
// that type. | ||
TypeSP type_sp = ParseTypeFromClangModule(sc, die, log); | ||
|
70 changes: 70 additions & 0 deletions
70
lldb/test/Shell/SymbolFile/DWARF/objcxx-forward-decls.test
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# REQUIRES: system-darwin | ||
|
||
# In this test we have two CUs with conflicting forward declaration | ||
# depending on the CU language (one is C++ and the other is Objective-C++). | ||
# We are then stopped in the C++ CU and try to print the type, at which | ||
# point LLDB will try to make it into an Clang AST node. If LLDB were to | ||
# interpret the type as C++ instead of Objective-C, we'd violate Clang | ||
# invariants and crash. | ||
# | ||
# RUN: split-file %s %t | ||
# RUN: %clangxx_host -c -g -x objective-c++ %t/request.m -o %t/request_objc.o | ||
# RUN: %clangxx_host -c -g %t/main.cpp -o %t/main.o | ||
# RUN: %clangxx_host %t/main.o %t/request_objc.o -framework Foundation -o %t/a.out | ||
# | ||
# RUN: %lldb %t/a.out \ | ||
# RUN: -o "breakpoint set -p return -X main" \ | ||
# RUN: -o run \ | ||
# RUN: -o "frame variable r" \ | ||
# RUN: -o exit | FileCheck %s | ||
# | ||
# RUN: dsymutil %t/a.out | ||
# | ||
# RUN: %lldb %t/a.out \ | ||
# RUN: -o "breakpoint set -p return -X main" \ | ||
# RUN: -o run \ | ||
# RUN: -o "frame variable r" \ | ||
# RUN: -o exit | FileCheck %s --check-prefix=CHECK-DSYM | ||
|
||
# CHECK: (lldb) frame variable r | ||
# CHECK-NEXT: (Request) ::r = (m_request = "Hello, World!") | ||
|
||
# CHECK-DSYM: (lldb) frame variable r | ||
# CHECK-DSYM-NEXT: (Request) ::r = (m_request = "Hello, World!") | ||
|
||
#--- lib.h | ||
#ifndef LIB_H_IN | ||
#define LIB_H_IN | ||
|
||
#ifdef __OBJC__ | ||
@class NSString; | ||
#else | ||
class NSString; | ||
#endif | ||
|
||
struct Request { | ||
NSString * m_request = nullptr; | ||
}; | ||
|
||
#endif // _H_IN | ||
|
||
#--- main.cpp | ||
#include "lib.h" | ||
|
||
void process(Request *); | ||
|
||
Request r; | ||
|
||
int main() { | ||
process(&r); | ||
return 0; | ||
} | ||
|
||
#--- request.m | ||
#import <Foundation/Foundation.h> | ||
|
||
#include "lib.h" | ||
|
||
void process(Request * r) { | ||
r->m_request = @"Hello, World!"; | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hoping we can be smarter about this lookup to not incur a big penalty for doing these type lookups
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also some filtering we got to do on the context, we only want to consider types in the global namespace