-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb] Analyze enum promotion type during parsing #115005
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
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
dd65bab
[lldb] Analyze enum promotion type during parsing
kuilpd b438c38
Fix enum's underlying type retrieval
kuilpd 4d60eec
Add a test
kuilpd 66d6074
Fix formatting
kuilpd 16ca7cf
Move enum type and width computations to a separate function
kuilpd 8fe2a9a
Use computeBestEnumTypes() from ASTContext & cleanup code
kuilpd 515ac84
Add comments
kuilpd 64fd77f
Apply clang-format
kuilpd a65d8c5
Move updating number of enum bits to a separate function
kuilpd 982cf25
Add dSYM to the test
kuilpd c5bc986
Move computing NumNegativeBits and NumPositiveBits to a separate func…
kuilpd 47532c9
Remove test skipping
kuilpd 2bfd311
Remove previous computeEnumBits implementation
kuilpd fe6a395
Move computing enum parameters to TypeSystemClang
kuilpd 88abe76
Move the computing code into the 'if' block
kuilpd 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
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,3 @@ | ||
CXX_SOURCES := main.cpp | ||
|
||
include Makefile.rules |
36 changes: 36 additions & 0 deletions
36
lldb/test/API/lang/cpp/enum_promotion/TestCPPEnumPromotion.py
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,36 @@ | ||
""" | ||
Test LLDB type promotion of unscoped enums. | ||
""" | ||
|
||
import lldb | ||
from lldbsuite.test.decorators import * | ||
from lldbsuite.test.lldbtest import * | ||
from lldbsuite.test import lldbutil | ||
|
||
|
||
class TestCPPEnumPromotion(TestBase): | ||
def test(self): | ||
self.build() | ||
lldbutil.run_to_source_breakpoint( | ||
self, "// break here", lldb.SBFileSpec("main.cpp") | ||
) | ||
UChar_promoted = self.frame().FindVariable("UChar_promoted") | ||
UShort_promoted = self.frame().FindVariable("UShort_promoted") | ||
UInt_promoted = self.frame().FindVariable("UInt_promoted") | ||
SLong_promoted = self.frame().FindVariable("SLong_promoted") | ||
ULong_promoted = self.frame().FindVariable("ULong_promoted") | ||
NChar_promoted = self.frame().FindVariable("NChar_promoted") | ||
NShort_promoted = self.frame().FindVariable("NShort_promoted") | ||
NInt_promoted = self.frame().FindVariable("NInt_promoted") | ||
NLong_promoted = self.frame().FindVariable("NLong_promoted") | ||
|
||
# Check that LLDB's promoted type is the same as the compiler's | ||
self.expect_expr("+EnumUChar::UChar", result_type=UChar_promoted.type.name) | ||
self.expect_expr("+EnumUShort::UShort", result_type=UShort_promoted.type.name) | ||
self.expect_expr("+EnumUInt::UInt", result_type=UInt_promoted.type.name) | ||
self.expect_expr("+EnumSLong::SLong", result_type=SLong_promoted.type.name) | ||
self.expect_expr("+EnumULong::ULong", result_type=ULong_promoted.type.name) | ||
self.expect_expr("+EnumNChar::NChar", result_type=NChar_promoted.type.name) | ||
self.expect_expr("+EnumNShort::NShort", result_type=NShort_promoted.type.name) | ||
self.expect_expr("+EnumNInt::NInt", result_type=NInt_promoted.type.name) | ||
self.expect_expr("+EnumNLong::NLong", result_type=NLong_promoted.type.name) |
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,22 @@ | ||
enum EnumUChar { UChar = 1 }; | ||
enum EnumUShort { UShort = 0x101 }; | ||
enum EnumUInt { UInt = 0x10001 }; | ||
enum EnumSLong { SLong = 0x100000001 }; | ||
enum EnumULong { ULong = 0xFFFFFFFFFFFFFFF0 }; | ||
enum EnumNChar { NChar = -1 }; | ||
enum EnumNShort { NShort = -0x101 }; | ||
enum EnumNInt { NInt = -0x10001 }; | ||
enum EnumNLong { NLong = -0x100000001 }; | ||
|
||
int main() { | ||
auto UChar_promoted = +EnumUChar::UChar; | ||
auto UShort_promoted = +EnumUShort::UShort; | ||
auto UInt_promoted = +EnumUInt::UInt; | ||
auto SLong_promoted = +EnumSLong::SLong; | ||
auto ULong_promoted = +EnumULong::ULong; | ||
auto NChar_promoted = +EnumNChar::NChar; | ||
auto NShort_promoted = +EnumNShort::NShort; | ||
auto NInt_promoted = +EnumNInt::NInt; | ||
auto NLong_promoted = +EnumNLong::NLong; | ||
return 0; // break here | ||
} |
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.
Can we move this block back into the
if (!integer_type.isNull()) {
condition below?