forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 342
Reland "[modules] Fix miscompilation when using two RecordDecl definitions with the same name." #3829
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
vsapsai
merged 1 commit into
stable/20211026
from
eng/PR-86548228-reland-recorddecl-miscompilation-fix
Mar 4, 2022
Merged
Reland "[modules] Fix miscompilation when using two RecordDecl definitions with the same name." #3829
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
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
21 changes: 21 additions & 0 deletions
21
clang/test/Modules/Inputs/merge-record-definition/RecordDef.framework/Headers/RecordDef.h
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,21 @@ | ||
// It is important to have a definition *after* non-definition declaration. | ||
typedef struct _Buffer Buffer; | ||
struct _Buffer { | ||
int a; | ||
int b; | ||
int c; | ||
}; | ||
|
||
typedef struct _AnonymousStruct AnonymousStruct; | ||
struct _AnonymousStruct { | ||
struct { | ||
int x; | ||
int y; | ||
}; | ||
}; | ||
|
||
typedef union _UnionRecord UnionRecord; | ||
union _UnionRecord { | ||
int u: 2; | ||
int v: 4; | ||
}; |
4 changes: 4 additions & 0 deletions
4
.../test/Modules/Inputs/merge-record-definition/RecordDef.framework/Modules/module.modulemap
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,4 @@ | ||
framework module RecordDef { | ||
header "RecordDef.h" | ||
export * | ||
} |
21 changes: 21 additions & 0 deletions
21
...st/Modules/Inputs/merge-record-definition/RecordDefCopy.framework/Headers/RecordDefCopy.h
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,21 @@ | ||
// It is important to have a definition *after* non-definition declaration. | ||
typedef struct _Buffer Buffer; | ||
struct _Buffer { | ||
int a; | ||
int b; | ||
int c; | ||
}; | ||
|
||
typedef struct _AnonymousStruct AnonymousStruct; | ||
struct _AnonymousStruct { | ||
struct { | ||
int x; | ||
int y; | ||
}; | ||
}; | ||
|
||
typedef union _UnionRecord UnionRecord; | ||
union _UnionRecord { | ||
int u: 2; | ||
int v: 4; | ||
}; |
4 changes: 4 additions & 0 deletions
4
...t/Modules/Inputs/merge-record-definition/RecordDefCopy.framework/Modules/module.modulemap
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,4 @@ | ||
framework module RecordDefCopy { | ||
header "RecordDefCopy.h" | ||
export * | ||
} |
21 changes: 21 additions & 0 deletions
21
clang/test/Modules/Inputs/merge-record-definition/RecordDefHidden.framework/Headers/Hidden.h
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,21 @@ | ||
// It is important to have a definition *after* non-definition declaration. | ||
typedef struct _Buffer Buffer; | ||
struct _Buffer { | ||
int a; | ||
int b; | ||
int c; | ||
}; | ||
|
||
typedef struct _AnonymousStruct AnonymousStruct; | ||
struct _AnonymousStruct { | ||
struct { | ||
int x; | ||
int y; | ||
}; | ||
}; | ||
|
||
typedef union _UnionRecord UnionRecord; | ||
union _UnionRecord { | ||
int u: 2; | ||
int v: 4; | ||
}; |
1 change: 1 addition & 0 deletions
1
...g/test/Modules/Inputs/merge-record-definition/RecordDefHidden.framework/Headers/Visible.h
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 @@ | ||
// Empty header to create a module. |
9 changes: 9 additions & 0 deletions
9
...Modules/Inputs/merge-record-definition/RecordDefHidden.framework/Modules/module.modulemap
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,9 @@ | ||
framework module RecordDefHidden { | ||
header "Visible.h" | ||
export * | ||
|
||
explicit module Hidden { | ||
header "Hidden.h" | ||
export * | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...es/Inputs/merge-record-definition/RecordDefIncluder.framework/Headers/RecordDefIncluder.h
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 @@ | ||
#import <RecordDef/RecordDef.h> |
4 changes: 4 additions & 0 deletions
4
...dules/Inputs/merge-record-definition/RecordDefIncluder.framework/Modules/module.modulemap
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,4 @@ | ||
framework module RecordDefIncluder { | ||
header "RecordDefIncluder.h" | ||
export * | ||
} |
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,39 @@ | ||
// UNSUPPORTED: -zos, -aix | ||
// RUN: rm -rf %t | ||
// RUN: mkdir %t | ||
// RUN: %clang_cc1 -emit-llvm -o %t/test.bc -F%S/Inputs/merge-record-definition %s \ | ||
// RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache -fmodule-name=RecordDef | ||
// RUN: %clang_cc1 -emit-llvm -o %t/test.bc -F%S/Inputs/merge-record-definition %s -DMODULAR_BEFORE_TEXTUAL \ | ||
// RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache -fmodule-name=RecordDef | ||
|
||
// Test a case when a struct definition once is included from a textual header and once from a module. | ||
|
||
#ifdef MODULAR_BEFORE_TEXTUAL | ||
#import <RecordDefIncluder/RecordDefIncluder.h> | ||
#else | ||
#import <RecordDef/RecordDef.h> | ||
#endif | ||
|
||
void bibi(void) { | ||
Buffer buf; | ||
buf.b = 1; | ||
AnonymousStruct strct; | ||
strct.x = 1; | ||
UnionRecord rec; | ||
rec.u = 1; | ||
} | ||
|
||
#ifdef MODULAR_BEFORE_TEXTUAL | ||
#import <RecordDef/RecordDef.h> | ||
#else | ||
#import <RecordDefIncluder/RecordDefIncluder.h> | ||
#endif | ||
|
||
void mbap(void) { | ||
Buffer buf; | ||
buf.c = 2; | ||
AnonymousStruct strct; | ||
strct.y = 2; | ||
UnionRecord rec; | ||
rec.v = 2; | ||
} |
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,19 @@ | ||
// UNSUPPORTED: -zos, -aix | ||
// RUN: rm -rf %t | ||
// RUN: mkdir %t | ||
// RUN: %clang_cc1 -emit-llvm -o %t/test.bc -F%S/Inputs/merge-record-definition %s \ | ||
// RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache | ||
|
||
// Test a case when a struct definition is first imported as invisible and then as visible. | ||
|
||
#import <RecordDefHidden/Visible.h> | ||
#import <RecordDef/RecordDef.h> | ||
|
||
void bibi(void) { | ||
Buffer buf; | ||
buf.b = 1; | ||
AnonymousStruct strct; | ||
strct.y = 1; | ||
UnionRecord rec; | ||
rec.u = 1; | ||
} |
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,29 @@ | ||
// UNSUPPORTED: -zos, -aix | ||
// RUN: rm -rf %t | ||
// RUN: mkdir %t | ||
// RUN: %clang_cc1 -emit-llvm -o %t/test.bc -F%S/Inputs/merge-record-definition %s \ | ||
// RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache | ||
|
||
// Test a case when a struct definition is present in two different modules. | ||
|
||
#import <RecordDef/RecordDef.h> | ||
|
||
void bibi(void) { | ||
Buffer buf; | ||
buf.b = 1; | ||
AnonymousStruct strct; | ||
strct.x = 1; | ||
UnionRecord rec; | ||
rec.u = 1; | ||
} | ||
|
||
#import <RecordDefCopy/RecordDefCopy.h> | ||
|
||
void mbap(void) { | ||
Buffer buf; | ||
buf.c = 2; | ||
AnonymousStruct strct; | ||
strct.y = 2; | ||
UnionRecord rec; | ||
rec.v = 2; | ||
} |
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.
Compared to the original patch I've changed this line from
RD->setCompleteDefinition(false);
toRD->demoteThisDefinitionToDeclaration();