-
Notifications
You must be signed in to change notification settings - Fork 11.7k
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
[Clang][CodeGen] Emit load of GEP after EmitMemberExpr #110487
Closed
+75
−0
Closed
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
375a71d
[Clang][CodeGen] Emit load of value
bwendling d07c992
Simplify the algorithm to look for a CK_LValueToRValue cast and stop …
bwendling 14de044
Merge branch 'llvm:main' into bdos-member-expr-error
bwendling 2de7647
Revert "Simplify the algorithm to look for a CK_LValueToRValue cast a…
bwendling 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 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 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 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,74 @@ | ||
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fstrict-flex-arrays=2 -emit-llvm -o - %s | FileCheck %s | ||
|
||
struct bch_val { | ||
unsigned long int __nothing[0]; | ||
}; | ||
|
||
struct bch_xattr { | ||
struct bch_val v; | ||
unsigned char x_type; | ||
unsigned char x_name_len; | ||
unsigned char x_name[] __attribute__((__counted_by__(x_name_len))); | ||
}; | ||
|
||
struct bkey_s_c { | ||
const struct bch_val *v; | ||
}; | ||
|
||
struct bkey_s_c_xattr { | ||
union { | ||
const struct bch_xattr *v; | ||
struct bkey_s_c s_c; | ||
}; | ||
}; | ||
|
||
// CHECK-LABEL: define dso_local i64 @test1( | ||
// CHECK-SAME: ptr [[K_COERCE:%.*]]) #[[ATTR0:[0-9]+]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[K:%.*]] = alloca [[STRUCT_BKEY_S_C:%.*]], align 8 | ||
// CHECK-NEXT: [[XATTR:%.*]] = alloca [[STRUCT_BKEY_S_C_XATTR:%.*]], align 8 | ||
// CHECK-NEXT: [[COERCE_DIVE:%.*]] = getelementptr inbounds nuw [[STRUCT_BKEY_S_C]], ptr [[K]], i32 0, i32 0 | ||
// CHECK-NEXT: store ptr [[K_COERCE]], ptr [[COERCE_DIVE]], align 8 | ||
// CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds nuw [[STRUCT_BKEY_S_C_XATTR]], ptr [[XATTR]], i32 0, i32 0 | ||
// CHECK-NEXT: [[V:%.*]] = getelementptr inbounds nuw [[STRUCT_BKEY_S_C]], ptr [[K]], i32 0, i32 0 | ||
// CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[V]], align 8 | ||
// CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds [[STRUCT_BCH_VAL:%.*]], ptr [[TMP1]], i64 0 | ||
// CHECK-NEXT: store ptr [[ADD_PTR]], ptr [[TMP0]], align 8 | ||
// CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds nuw [[STRUCT_BKEY_S_C_XATTR]], ptr [[XATTR]], i32 0, i32 0 | ||
// CHECK-NEXT: [[TMP3:%.*]] = load ptr, ptr [[TMP2]], align 8 | ||
// CHECK-NEXT: [[DOT_COUNTED_BY_GEP:%.*]] = getelementptr inbounds [[STRUCT_BCH_XATTR:%.*]], ptr [[TMP3]], i32 0, i32 2 | ||
// CHECK-NEXT: [[DOT_COUNTED_BY_LOAD:%.*]] = load i8, ptr [[DOT_COUNTED_BY_GEP]], align 4 | ||
// CHECK-NEXT: [[TMP4:%.*]] = zext i8 [[DOT_COUNTED_BY_LOAD]] to i64 | ||
// CHECK-NEXT: [[TMP5:%.*]] = mul nuw i64 [[TMP4]], 1 | ||
// CHECK-NEXT: [[TMP6:%.*]] = icmp sgt i64 [[TMP4]], -1 | ||
// CHECK-NEXT: [[TMP7:%.*]] = select i1 [[TMP6]], i64 [[TMP5]], i64 0 | ||
// CHECK-NEXT: ret i64 [[TMP7]] | ||
// | ||
unsigned long int test1(struct bkey_s_c k) { | ||
struct bkey_s_c_xattr xattr = (struct bkey_s_c_xattr){ | ||
.v = (struct bch_xattr *)(k.v - __builtin_offsetof(struct bch_xattr, v)) | ||
}; | ||
|
||
return __builtin_dynamic_object_size(xattr.v->x_name, 0); | ||
} | ||
|
||
// CHECK-LABEL: define dso_local i64 @test2( | ||
// CHECK-SAME: ptr noundef [[XATTR:%.*]]) #[[ATTR0]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[XATTR_ADDR:%.*]] = alloca ptr, align 8 | ||
// CHECK-NEXT: store ptr [[XATTR]], ptr [[XATTR_ADDR]], align 8 | ||
// CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[XATTR_ADDR]], align 8 | ||
// CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds nuw [[STRUCT_BKEY_S_C_XATTR:%.*]], ptr [[TMP0]], i32 0, i32 0 | ||
// CHECK-NEXT: [[TMP2:%.*]] = load ptr, ptr [[TMP1]], align 8 | ||
// CHECK-NEXT: [[DOT_COUNTED_BY_GEP:%.*]] = getelementptr inbounds [[STRUCT_BCH_XATTR:%.*]], ptr [[TMP2]], i32 0, i32 2 | ||
// CHECK-NEXT: [[DOT_COUNTED_BY_LOAD:%.*]] = load i8, ptr [[DOT_COUNTED_BY_GEP]], align 4 | ||
// CHECK-NEXT: [[TMP3:%.*]] = zext i8 [[DOT_COUNTED_BY_LOAD]] to i64 | ||
// CHECK-NEXT: [[TMP4:%.*]] = mul nuw i64 [[TMP3]], 1 | ||
// CHECK-NEXT: [[TMP5:%.*]] = icmp sgt i64 [[TMP3]], -1 | ||
// CHECK-NEXT: [[TMP6:%.*]] = select i1 [[TMP5]], i64 [[TMP4]], i64 0 | ||
// CHECK-NEXT: ret i64 [[TMP6]] | ||
// | ||
unsigned long int test2(struct bkey_s_c_xattr *xattr) { | ||
return __builtin_dynamic_object_size(xattr->v->x_name, 0); | ||
} |
This file contains 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 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
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.
In the example C file that causes the compiler to segfault,
StructBase
is not a pointer here, so this fails.Here's a dump of StructBase:
So you have to distinguish between the MemberExpr and the pointer case right here, at which point you are basically back to my PR (although I guess the case for
DeclRefExpr
can be removed additionally; that does break tests, so I'll check carefully it the behavior is still correct with that case removed)