-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[CIR] Upstream trivial constructor const handling #164849
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
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++11 -fclangir -emit-cir %s -o %t.cir | ||
| // RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR | ||
| // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++11 -fclangir -emit-llvm %s -o %t-cir.ll | ||
| // RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM | ||
| // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++11 -emit-llvm %s -o %t.ll | ||
| // RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG | ||
|
|
||
| struct StructWithDefaultCtor { | ||
| int n; | ||
| }; | ||
|
|
||
| StructWithDefaultCtor defCtor = StructWithDefaultCtor(); | ||
|
|
||
| // CIR: cir.global {{.*}} @defCtor = #cir.zero : !rec_StructWithDefaultCtor | ||
| // LLVM: @defCtor = global %struct.StructWithDefaultCtor zeroinitializer | ||
| // OGCG: @defCtor = global %struct.StructWithDefaultCtor zeroinitializer | ||
|
|
||
| struct StructWithCtorArg { | ||
| double value; | ||
| StructWithCtorArg(const double& x) : value(x) {} | ||
| }; | ||
|
|
||
| StructWithCtorArg withArg = 0.0; | ||
|
|
||
| // CIR: cir.global {{.*}} @withArg = #cir.zero : !rec_StructWithCtorArg | ||
| // LLVM: @withArg = global %struct.StructWithCtorArg zeroinitializer | ||
| // OGCG: @withArg = global %struct.StructWithCtorArg zeroinitializer | ||
|
|
||
| // CIR: cir.func {{.*}} @__cxx_global_var_init() | ||
| // CIR: %[[TMP0:.*]] = cir.alloca !cir.double, !cir.ptr<!cir.double>, ["ref.tmp0"] | ||
| // CIR: %[[WITH_ARG:.*]] = cir.get_global @withArg : !cir.ptr<!rec_StructWithCtorArg> | ||
| // CIR: %[[ZERO:.*]] = cir.const #cir.fp<0.000000e+00> : !cir.double | ||
| // CIR: cir.store{{.*}} %[[ZERO]], %[[TMP0]] : !cir.double, !cir.ptr<!cir.double> | ||
| // CIR: cir.call @_ZN17StructWithCtorArgC1ERKd(%[[WITH_ARG]], %[[TMP0]]) : (!cir.ptr<!rec_StructWithCtorArg>, !cir.ptr<!cir.double>) -> () | ||
|
|
||
| // LLVM: define {{.*}} void @__cxx_global_var_init() | ||
| // LLVM: %[[TMP0:.*]] = alloca double | ||
| // LLVM: store double 0.000000e+00, ptr %[[TMP0]] | ||
| // LLVM: call void @_ZN17StructWithCtorArgC1ERKd(ptr @withArg, ptr %[[TMP0]]) | ||
|
|
||
| // OGCG: define {{.*}} void @__cxx_global_var_init() | ||
| // OGCG: %[[TMP0:.*]] = alloca double | ||
| // OGCG: store double 0.000000e+00, ptr %[[TMP0]] | ||
| // OGCG: call void @_ZN17StructWithCtorArgC1ERKd(ptr {{.*}} @withArg, ptr {{.*}} %[[TMP0]]) |
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.
Should this be a not-yet-implemented or something?
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.
This comment is carried over from classic codegen, which does the same thing here.
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.
Oh weird... Can you replace the dyn_cast with a cast in classic codegen? Does it hit anything? I'm actually pretty concerned by this...
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.
If I report and error after the dyn_cast falls through in classic codegen, it fires 14 times in eight tests in the CodeGenCXX tests:
llvm-project/clang/test/CodeGenCXX/microsoft-uuidof.cpp
Line 44 in a909ec6
llvm-project/clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
Line 214 in a909ec6
llvm-project/clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
Line 245 in a909ec6
llvm-project/clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
Line 250 in a909ec6
llvm-project/clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
Line 304 in a909ec6
llvm-project/clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
Line 321 in a909ec6
llvm-project/clang/test/CodeGenCXX/atomicinit.cpp
Line 117 in a909ec6
llvm-project/clang/test/CodeGenCXX/reference-init.cpp
Line 38 in a909ec6
llvm-project/clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp
Line 44 in a909ec6
llvm-project/clang/test/CodeGenCXX/cxx1z-decomposition.cpp
Line 34 in a909ec6
llvm-project/clang/test/CodeGenCXX/cxx1z-decomposition.cpp
Line 122 in a909ec6
llvm-project/clang/test/CodeGenCXX/cxx1z-decomposition.cpp
Line 138 in a909ec6
llvm-project/clang/test/CodeGenCXX/static-init-3.cpp
Line 27 in a909ec6
llvm-project/clang/test/CodeGenCXX/copy-constructor-synthesis-2.cpp
Line 11 in a909ec6
I haven't looked at these in detail yet, but I know that we can get here if the constructor argument is not a constant, and if we do then returning nullptr is the correct behavior.
The only case that would be a problem is if the argument is not a
MaterializeTemporaryExprbut is a constant, and even in that case if we return null here, something else is going to handle it, though possibly not correctly.I also tried inserting a call to
ConstantExprEmitter::Visit(Arg, Ty)in the case where the dyn_cast failed, and that doesn't change anything.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.
One possible alternative is to add a missing feature as a way to track what needs to be investigated into both CodeGen paths.