-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[C11] Implement WG14 N1285 (temporary lifetimes) #133472
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 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f9268b3
[C11] Implement WG14 N1285 (temporary lifetimes)
AaronBallman 54a7a06
Fix codegen
AaronBallman 22b87ac
Fix formatting; NFC
AaronBallman 15b3f7b
Back out unnecessary changes
AaronBallman 94b396c
Speculative fix for codegen test
AaronBallman 59aa0a7
Fix formatting, fix test
AaronBallman c3a8366
Add codegen test with lifetime markers
AaronBallman 7c26403
Disable LLVM passes
AaronBallman cc08174
Remove escape
AaronBallman 9d2e2e3
Merge remote-tracking branch 'origin/main' into aballman-wg14-n1285
AaronBallman 386b23e
Backport to earlier C language modes
AaronBallman f053763
Reorder comment; NFC
AaronBallman 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
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 |
|---|---|---|
| @@ -1,24 +1,81 @@ | ||
| // RUN: %clang_cc1 -verify=wrong -std=c99 %s | ||
| // RUN: %clang_cc1 -verify=wrong -std=c11 %s | ||
| // RUN: %clang_cc1 -verify=cpp -std=c++11 -x c++ %s | ||
| // RUN: %clang_cc1 -fsyntax-only -verify=good -std=c99 %s | ||
| // RUN: %clang_cc1 -fsyntax-only -verify=expected,c -std=c11 %s | ||
| // RUN: %clang_cc1 -fsyntax-only -verify=expected,cpp -std=c++11 -x c++ %s | ||
|
|
||
| /* WG14 N1285: No | ||
| /* WG14 N1285: Clang 21 | ||
| * Extending the lifetime of temporary objects (factored approach) | ||
| * | ||
| * NB: we do not properly materialize temporary expressions in situations where | ||
| * it would be expected; that is why the "no-diagnostics" marking is named | ||
| * "wrong". We do issue the expected diagnostic in C++ mode. | ||
| * This paper introduced the notion of an object with a temporary lifetime. Any | ||
| * operation resulting in an rvalue of structure or union type which contains | ||
| * an array results in an object with temporary lifetime. | ||
| */ | ||
|
|
||
| // wrong-no-diagnostics | ||
| // good-no-diagnostics | ||
|
|
||
| // C11 6.2.4p8: A non-lvalue expression with structure or union type, where the | ||
| // structure or union contains a member with array type (including, | ||
| // recursively, members of all contained structures and unions) refers to an | ||
| // object with automatic storage duration and temporary lifetime. Its lifetime | ||
| // begins when the expression is evaluated and its initial value is the value | ||
| // of the expression. Its lifetime ends when the evaluation of the containing | ||
| // full expression or full declarator ends. Any attempt to modify an object | ||
| // with temporary lifetime results in undefined behavior. | ||
|
|
||
| struct X { int a[5]; }; | ||
| struct X f(void); | ||
|
|
||
| int foo(void) { | ||
| // FIXME: This diagnostic should be issued in C11 as well (though not in C99, | ||
| // as this paper was a breaking change between C99 and C11). | ||
| int *p = f().a; // cpp-warning {{temporary whose address is used as value of local variable 'p' will be destroyed at the end of the full-expression}} | ||
| return *p; | ||
| union U { int a[10]; double d; }; | ||
| union U g(void); | ||
|
|
||
| void sink(int *); | ||
|
|
||
| int func_return(void) { | ||
| int *p = f().a; // expected-warning {{temporary whose address is used as value of local variable 'p' will be destroyed at the end of the full-expression}} | ||
| p = f().a; // expected-warning {{object backing the pointer p will be destroyed at the end of the full-expression}} | ||
| p = g().a; // expected-warning {{object backing the pointer p will be destroyed at the end of the full-expression}} | ||
| sink(f().a); // Ok | ||
| return *f().a; // Ok | ||
| } | ||
|
|
||
| int ternary(void) { | ||
| int *p = (1 ? (struct X){ 0 } : f()).a; // expected-warning {{temporary whose address is used as value of local variable 'p' will be destroyed at the end of the full-expression}} | ||
| int *r = (1 ? (union U){ 0 } : g()).a; // expected-warning {{temporary whose address is used as value of local variable 'r' will be destroyed at the end of the full-expression}} | ||
| p = (1 ? (struct X){ 0 } : f()).a; // expected-warning {{object backing the pointer p will be destroyed at the end of the full-expression}} | ||
| sink((1 ? (struct X){ 0 } : f()).a); // Ok | ||
|
|
||
| // This intentionally gets one diagnostic in C and two in C++. In C, the | ||
| // compound literal results in an lvalue, not an rvalue as it does in C++. So | ||
| // only one branch results in a temporary in C but both branches do in C++. | ||
| int *q = 1 ? (struct X){ 0 }.a : f().a; // expected-warning {{temporary whose address is used as value of local variable 'q' will be destroyed at the end of the full-expression}} \ | ||
| cpp-warning {{temporary whose address is used as value of local variable 'q' will be destroyed at the end of the full-expression}} | ||
| q = 1 ? (struct X){ 0 }.a : f().a; // expected-warning {{object backing the pointer q will be destroyed at the end of the full-expression}} \ | ||
| cpp-warning {{object backing the pointer q will be destroyed at the end of the full-expression}} | ||
| q = 1 ? (struct X){ 0 }.a : g().a; // expected-warning {{object backing the pointer q will be destroyed at the end of the full-expression}} \ | ||
| cpp-warning {{object backing the pointer q will be destroyed at the end of the full-expression}} | ||
| sink(1 ? (struct X){ 0 }.a : f().a); // Ok | ||
| return *(1 ? (struct X){ 0 }.a : f().a); // Ok | ||
| } | ||
|
|
||
| int comma(void) { | ||
| struct X x; | ||
| int *p = ((void)0, x).a; // c-warning {{temporary whose address is used as value of local variable 'p' will be destroyed at the end of the full-expression}} | ||
| p = ((void)0, x).a; // c-warning {{object backing the pointer p will be destroyed at the end of the full-expression}} | ||
| sink(((void)0, x).a); // Ok | ||
| return *(((void)0, x).a);// Ok | ||
| } | ||
|
|
||
| int cast(void) { | ||
| struct X x; | ||
| int *p = ((struct X)x).a; // expected-warning {{temporary whose address is used as value of local variable 'p' will be destroyed at the end of the full-expression}} | ||
| p = ((struct X)x).a; // expected-warning {{object backing the pointer p will be destroyed at the end of the full-expression}} | ||
| sink(((struct X)x).a); // Ok | ||
| return *(((struct X)x).a); // Ok | ||
| } | ||
|
|
||
| int assign(void) { | ||
| struct X x, s; | ||
| int *p = (x = s).a; // c-warning {{temporary whose address is used as value of local variable 'p' will be destroyed at the end of the full-expression}} | ||
| p = (x = s).a; // c-warning {{object backing the pointer p will be destroyed at the end of the full-expression}} | ||
| sink((x = s).a); // Ok | ||
| return *((x = s).a); // Ok | ||
| } |
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,212 @@ | ||
| // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 | ||
| // RUN: %clang_cc1 -std=c99 -Wno-dangling -emit-llvm -o - %s | FileCheck %s --check-prefix=C99 | ||
| // RUN: %clang_cc1 -std=c11 -Wno-dangling -emit-llvm -o - %s | FileCheck %s --check-prefix=C11 | ||
AaronBallman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Ensure that codegen for temporary lifetimes makes sense. | ||
|
|
||
| struct X { int a[5]; }; | ||
| struct X f(void); | ||
|
|
||
| // C99-LABEL: define dso_local i32 @func_return( | ||
| // C99-SAME: ) #[[ATTR0:[0-9]+]] { | ||
| // C99-NEXT: [[ENTRY:.*:]] | ||
| // C99-NEXT: [[P:%.*]] = alloca ptr, align 8 | ||
| // C99-NEXT: [[TMP:%.*]] = alloca [[STRUCT_X:%.*]], align 4 | ||
| // C99-NEXT: call void @f(ptr dead_on_unwind writable sret([[STRUCT_X]]) align 4 [[TMP]]) | ||
| // C99-NEXT: [[A:%.*]] = getelementptr inbounds nuw [[STRUCT_X]], ptr [[TMP]], i32 0, i32 0 | ||
| // C99-NEXT: [[ARRAYDECAY:%.*]] = getelementptr inbounds [5 x i32], ptr [[A]], i64 0, i64 0 | ||
| // C99-NEXT: store ptr [[ARRAYDECAY]], ptr [[P]], align 8 | ||
| // C99-NEXT: [[TMP0:%.*]] = load ptr, ptr [[P]], align 8 | ||
| // C99-NEXT: [[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4 | ||
| // C99-NEXT: ret i32 [[TMP1]] | ||
| // | ||
| // C11-LABEL: define dso_local i32 @func_return( | ||
| // C11-SAME: ) #[[ATTR0:[0-9]+]] { | ||
| // C11-NEXT: [[ENTRY:.*:]] | ||
| // C11-NEXT: [[P:%.*]] = alloca ptr, align 8 | ||
| // C11-NEXT: [[REF_TMP:%.*]] = alloca [[STRUCT_X:%.*]], align 4 | ||
| // C11-NEXT: call void @f(ptr dead_on_unwind writable sret([[STRUCT_X]]) align 4 [[REF_TMP]]) | ||
| // C11-NEXT: [[A:%.*]] = getelementptr inbounds nuw [[STRUCT_X]], ptr [[REF_TMP]], i32 0, i32 0 | ||
| // C11-NEXT: [[ARRAYDECAY:%.*]] = getelementptr inbounds [5 x i32], ptr [[A]], i64 0, i64 0 | ||
| // C11-NEXT: store ptr [[ARRAYDECAY]], ptr [[P]], align 8 | ||
| // C11-NEXT: [[TMP0:%.*]] = load ptr, ptr [[P]], align 8 | ||
| // C11-NEXT: [[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4 | ||
| // C11-NEXT: ret i32 [[TMP1]] | ||
| // | ||
| int func_return(void) { | ||
| int *p = f().a; | ||
| return *p; | ||
| } | ||
|
|
||
| // C99-LABEL: define dso_local i32 @ternary( | ||
| // C99-SAME: ) #[[ATTR0]] { | ||
| // C99-NEXT: [[ENTRY:.*:]] | ||
| // C99-NEXT: [[P:%.*]] = alloca ptr, align 8 | ||
| // C99-NEXT: [[TMP:%.*]] = alloca [[STRUCT_X:%.*]], align 4 | ||
| // C99-NEXT: [[Q:%.*]] = alloca ptr, align 8 | ||
| // C99-NEXT: [[DOTCOMPOUNDLITERAL:%.*]] = alloca [[STRUCT_X]], align 4 | ||
| // C99-NEXT: br i1 true, label %[[COND_TRUE:.*]], label %[[COND_FALSE:.*]] | ||
| // C99: [[COND_TRUE]]: | ||
| // C99-NEXT: call void @llvm.memset.p0.i64(ptr align 4 [[TMP]], i8 0, i64 20, i1 false) | ||
| // C99-NEXT: [[A:%.*]] = getelementptr inbounds nuw [[STRUCT_X]], ptr [[TMP]], i32 0, i32 0 | ||
| // C99-NEXT: br label %[[COND_END:.*]] | ||
| // C99: [[COND_FALSE]]: | ||
| // C99-NEXT: call void @f(ptr dead_on_unwind writable sret([[STRUCT_X]]) align 4 [[TMP]]) | ||
| // C99-NEXT: br label %[[COND_END]] | ||
| // C99: [[COND_END]]: | ||
| // C99-NEXT: [[A1:%.*]] = getelementptr inbounds nuw [[STRUCT_X]], ptr [[TMP]], i32 0, i32 0 | ||
| // C99-NEXT: [[ARRAYDECAY:%.*]] = getelementptr inbounds [5 x i32], ptr [[A1]], i64 0, i64 0 | ||
| // C99-NEXT: store ptr [[ARRAYDECAY]], ptr [[P]], align 8 | ||
| // C99-NEXT: call void @llvm.memset.p0.i64(ptr align 4 [[DOTCOMPOUNDLITERAL]], i8 0, i64 20, i1 false) | ||
| // C99-NEXT: [[A2:%.*]] = getelementptr inbounds nuw [[STRUCT_X]], ptr [[DOTCOMPOUNDLITERAL]], i32 0, i32 0 | ||
| // C99-NEXT: [[A3:%.*]] = getelementptr inbounds nuw [[STRUCT_X]], ptr [[DOTCOMPOUNDLITERAL]], i32 0, i32 0 | ||
| // C99-NEXT: [[ARRAYDECAY4:%.*]] = getelementptr inbounds [5 x i32], ptr [[A3]], i64 0, i64 0 | ||
| // C99-NEXT: store ptr [[ARRAYDECAY4]], ptr [[Q]], align 8 | ||
| // C99-NEXT: [[TMP0:%.*]] = load ptr, ptr [[P]], align 8 | ||
| // C99-NEXT: [[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4 | ||
| // C99-NEXT: [[TMP2:%.*]] = load ptr, ptr [[Q]], align 8 | ||
| // C99-NEXT: [[TMP3:%.*]] = load i32, ptr [[TMP2]], align 4 | ||
| // C99-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP1]], [[TMP3]] | ||
| // C99-NEXT: ret i32 [[ADD]] | ||
| // | ||
| // C11-LABEL: define dso_local i32 @ternary( | ||
| // C11-SAME: ) #[[ATTR0]] { | ||
| // C11-NEXT: [[ENTRY:.*:]] | ||
| // C11-NEXT: [[P:%.*]] = alloca ptr, align 8 | ||
| // C11-NEXT: [[REF_TMP:%.*]] = alloca [[STRUCT_X:%.*]], align 4 | ||
| // C11-NEXT: [[Q:%.*]] = alloca ptr, align 8 | ||
| // C11-NEXT: [[DOTCOMPOUNDLITERAL:%.*]] = alloca [[STRUCT_X]], align 4 | ||
| // C11-NEXT: br i1 true, label %[[COND_TRUE:.*]], label %[[COND_FALSE:.*]] | ||
| // C11: [[COND_TRUE]]: | ||
| // C11-NEXT: call void @llvm.memset.p0.i64(ptr align 4 [[REF_TMP]], i8 0, i64 20, i1 false) | ||
| // C11-NEXT: [[A:%.*]] = getelementptr inbounds nuw [[STRUCT_X]], ptr [[REF_TMP]], i32 0, i32 0 | ||
| // C11-NEXT: br label %[[COND_END:.*]] | ||
| // C11: [[COND_FALSE]]: | ||
| // C11-NEXT: call void @f(ptr dead_on_unwind writable sret([[STRUCT_X]]) align 4 [[REF_TMP]]) | ||
| // C11-NEXT: br label %[[COND_END]] | ||
| // C11: [[COND_END]]: | ||
| // C11-NEXT: [[A1:%.*]] = getelementptr inbounds nuw [[STRUCT_X]], ptr [[REF_TMP]], i32 0, i32 0 | ||
| // C11-NEXT: [[ARRAYDECAY:%.*]] = getelementptr inbounds [5 x i32], ptr [[A1]], i64 0, i64 0 | ||
| // C11-NEXT: store ptr [[ARRAYDECAY]], ptr [[P]], align 8 | ||
| // C11-NEXT: call void @llvm.memset.p0.i64(ptr align 4 [[DOTCOMPOUNDLITERAL]], i8 0, i64 20, i1 false) | ||
| // C11-NEXT: [[A2:%.*]] = getelementptr inbounds nuw [[STRUCT_X]], ptr [[DOTCOMPOUNDLITERAL]], i32 0, i32 0 | ||
| // C11-NEXT: [[A3:%.*]] = getelementptr inbounds nuw [[STRUCT_X]], ptr [[DOTCOMPOUNDLITERAL]], i32 0, i32 0 | ||
| // C11-NEXT: [[ARRAYDECAY4:%.*]] = getelementptr inbounds [5 x i32], ptr [[A3]], i64 0, i64 0 | ||
| // C11-NEXT: store ptr [[ARRAYDECAY4]], ptr [[Q]], align 8 | ||
| // C11-NEXT: [[TMP0:%.*]] = load ptr, ptr [[P]], align 8 | ||
| // C11-NEXT: [[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4 | ||
| // C11-NEXT: [[TMP2:%.*]] = load ptr, ptr [[Q]], align 8 | ||
| // C11-NEXT: [[TMP3:%.*]] = load i32, ptr [[TMP2]], align 4 | ||
| // C11-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP1]], [[TMP3]] | ||
| // C11-NEXT: ret i32 [[ADD]] | ||
| // | ||
| int ternary(void) { | ||
| int *p; | ||
| p = (1 ? (struct X){ 0 } : f()).a; | ||
| int *q = 1 ? (struct X){ 0 }.a : f().a; | ||
|
|
||
| return *p + *q; | ||
| } | ||
|
|
||
| // C99-LABEL: define dso_local i32 @comma( | ||
| // C99-SAME: ) #[[ATTR0]] { | ||
| // C99-NEXT: [[ENTRY:.*:]] | ||
| // C99-NEXT: [[X:%.*]] = alloca [[STRUCT_X:%.*]], align 4 | ||
| // C99-NEXT: [[P:%.*]] = alloca ptr, align 8 | ||
| // C99-NEXT: [[A:%.*]] = getelementptr inbounds nuw [[STRUCT_X]], ptr [[X]], i32 0, i32 0 | ||
| // C99-NEXT: [[ARRAYDECAY:%.*]] = getelementptr inbounds [5 x i32], ptr [[A]], i64 0, i64 0 | ||
| // C99-NEXT: store ptr [[ARRAYDECAY]], ptr [[P]], align 8 | ||
| // C99-NEXT: [[TMP0:%.*]] = load ptr, ptr [[P]], align 8 | ||
| // C99-NEXT: [[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4 | ||
| // C99-NEXT: ret i32 [[TMP1]] | ||
| // | ||
| // C11-LABEL: define dso_local i32 @comma( | ||
| // C11-SAME: ) #[[ATTR0]] { | ||
| // C11-NEXT: [[ENTRY:.*:]] | ||
| // C11-NEXT: [[X:%.*]] = alloca [[STRUCT_X:%.*]], align 4 | ||
| // C11-NEXT: [[P:%.*]] = alloca ptr, align 8 | ||
| // C11-NEXT: [[REF_TMP:%.*]] = alloca [[STRUCT_X]], align 4 | ||
| // C11-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[REF_TMP]], ptr align 4 [[X]], i64 20, i1 false) | ||
| // C11-NEXT: [[A:%.*]] = getelementptr inbounds nuw [[STRUCT_X]], ptr [[REF_TMP]], i32 0, i32 0 | ||
| // C11-NEXT: [[ARRAYDECAY:%.*]] = getelementptr inbounds [5 x i32], ptr [[A]], i64 0, i64 0 | ||
| // C11-NEXT: store ptr [[ARRAYDECAY]], ptr [[P]], align 8 | ||
| // C11-NEXT: [[TMP0:%.*]] = load ptr, ptr [[P]], align 8 | ||
| // C11-NEXT: [[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4 | ||
| // C11-NEXT: ret i32 [[TMP1]] | ||
| // | ||
| int comma(void) { | ||
| struct X x; | ||
| int *p = ((void)0, x).a; | ||
| return *p; | ||
| } | ||
|
|
||
| // C99-LABEL: define dso_local i32 @cast( | ||
| // C99-SAME: ) #[[ATTR0]] { | ||
| // C99-NEXT: [[ENTRY:.*:]] | ||
| // C99-NEXT: [[X:%.*]] = alloca [[STRUCT_X:%.*]], align 4 | ||
| // C99-NEXT: [[P:%.*]] = alloca ptr, align 8 | ||
| // C99-NEXT: [[A:%.*]] = getelementptr inbounds nuw [[STRUCT_X]], ptr [[X]], i32 0, i32 0 | ||
| // C99-NEXT: [[ARRAYDECAY:%.*]] = getelementptr inbounds [5 x i32], ptr [[A]], i64 0, i64 0 | ||
| // C99-NEXT: store ptr [[ARRAYDECAY]], ptr [[P]], align 8 | ||
| // C99-NEXT: [[TMP0:%.*]] = load ptr, ptr [[P]], align 8 | ||
| // C99-NEXT: [[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4 | ||
| // C99-NEXT: ret i32 [[TMP1]] | ||
| // | ||
| // C11-LABEL: define dso_local i32 @cast( | ||
| // C11-SAME: ) #[[ATTR0]] { | ||
| // C11-NEXT: [[ENTRY:.*:]] | ||
| // C11-NEXT: [[X:%.*]] = alloca [[STRUCT_X:%.*]], align 4 | ||
| // C11-NEXT: [[P:%.*]] = alloca ptr, align 8 | ||
| // C11-NEXT: [[REF_TMP:%.*]] = alloca [[STRUCT_X]], align 4 | ||
| // C11-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[REF_TMP]], ptr align 4 [[X]], i64 20, i1 false) | ||
| // C11-NEXT: [[A:%.*]] = getelementptr inbounds nuw [[STRUCT_X]], ptr [[REF_TMP]], i32 0, i32 0 | ||
| // C11-NEXT: [[ARRAYDECAY:%.*]] = getelementptr inbounds [5 x i32], ptr [[A]], i64 0, i64 0 | ||
| // C11-NEXT: store ptr [[ARRAYDECAY]], ptr [[P]], align 8 | ||
| // C11-NEXT: [[TMP0:%.*]] = load ptr, ptr [[P]], align 8 | ||
| // C11-NEXT: [[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4 | ||
| // C11-NEXT: ret i32 [[TMP1]] | ||
| // | ||
| int cast(void) { | ||
| struct X x; | ||
| int *p; | ||
| p = ((struct X)x).a; | ||
| return *p; | ||
| } | ||
|
|
||
| // C99-LABEL: define dso_local i32 @assign( | ||
| // C99-SAME: ) #[[ATTR0]] { | ||
| // C99-NEXT: [[ENTRY:.*:]] | ||
| // C99-NEXT: [[X:%.*]] = alloca [[STRUCT_X:%.*]], align 4 | ||
| // C99-NEXT: [[S:%.*]] = alloca [[STRUCT_X]], align 4 | ||
| // C99-NEXT: [[P:%.*]] = alloca ptr, align 8 | ||
| // C99-NEXT: [[TMP:%.*]] = alloca [[STRUCT_X]], align 4 | ||
| // C99-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[X]], ptr align 4 [[S]], i64 20, i1 false) | ||
| // C99-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[TMP]], ptr align 4 [[X]], i64 20, i1 false) | ||
| // C99-NEXT: [[A:%.*]] = getelementptr inbounds nuw [[STRUCT_X]], ptr [[TMP]], i32 0, i32 0 | ||
| // C99-NEXT: [[ARRAYDECAY:%.*]] = getelementptr inbounds [5 x i32], ptr [[A]], i64 0, i64 0 | ||
| // C99-NEXT: store ptr [[ARRAYDECAY]], ptr [[P]], align 8 | ||
| // C99-NEXT: [[TMP0:%.*]] = load ptr, ptr [[P]], align 8 | ||
| // C99-NEXT: [[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4 | ||
| // C99-NEXT: ret i32 [[TMP1]] | ||
| // | ||
| // C11-LABEL: define dso_local i32 @assign( | ||
| // C11-SAME: ) #[[ATTR0]] { | ||
| // C11-NEXT: [[ENTRY:.*:]] | ||
| // C11-NEXT: [[X:%.*]] = alloca [[STRUCT_X:%.*]], align 4 | ||
| // C11-NEXT: [[S:%.*]] = alloca [[STRUCT_X]], align 4 | ||
| // C11-NEXT: [[P:%.*]] = alloca ptr, align 8 | ||
| // C11-NEXT: [[REF_TMP:%.*]] = alloca [[STRUCT_X]], align 4 | ||
| // C11-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[X]], ptr align 4 [[S]], i64 20, i1 false) | ||
| // C11-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[REF_TMP]], ptr align 4 [[X]], i64 20, i1 false) | ||
| // C11-NEXT: [[A:%.*]] = getelementptr inbounds nuw [[STRUCT_X]], ptr [[REF_TMP]], i32 0, i32 0 | ||
| // C11-NEXT: [[ARRAYDECAY:%.*]] = getelementptr inbounds [5 x i32], ptr [[A]], i64 0, i64 0 | ||
| // C11-NEXT: store ptr [[ARRAYDECAY]], ptr [[P]], align 8 | ||
| // C11-NEXT: [[TMP0:%.*]] = load ptr, ptr [[P]], align 8 | ||
| // C11-NEXT: [[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4 | ||
| // C11-NEXT: ret i32 [[TMP1]] | ||
| // | ||
| int assign(void) { | ||
| struct X x, s; | ||
| int *p = (x = s).a; | ||
| return *p; | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.