-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[CIR] Add name for enum type in vtable #163612
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
Conversation
@llvm/pr-subscribers-clangir Author: Omar Hossam (moar55) ChangesThis commit adds the RTTI support for enum in the vtable. Full diff: https://github.com/llvm/llvm-project/pull/163612.diff 2 Files Affected:
diff --git a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
index 9bb1fe1d49a25..276675cbca5f5 100644
--- a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
@@ -952,8 +952,7 @@ const char *vTableClassNameForType(const CIRGenModule &cgm, const Type *ty) {
break;
case Type::Enum:
- cgm.errorNYI("VTableClassNameForType: Enum");
- break;
+ return "_ZTVN10__cxxabiv116__enum_type_infoE";
case Type::Record: {
const CXXRecordDecl *rd =
diff --git a/clang/test/CIR/CodeGen/throws.cpp b/clang/test/CIR/CodeGen/throws.cpp
index 4255d436d4a32..f8aa965b1a4aa 100644
--- a/clang/test/CIR/CodeGen/throws.cpp
+++ b/clang/test/CIR/CodeGen/throws.cpp
@@ -144,3 +144,52 @@ void throw_complex_expr() {
// OGCG: store float 0x3FF19999A0000000, ptr %[[EXCEPTION_REAL]], align 16
// OGCG: store float 0x40019999A0000000, ptr %[[EXCEPTION_IMAG]], align 4
// OGCG: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR]], ptr @_ZTICf, ptr null)
+
+
+void throw_enum_expr() {
+ enum Test {
+ TestA,
+ TestB
+ };
+ throw Test::TestA;
+}
+
+//CIR: %[[EXCEPTION_ADDR:.*]] = cir.alloc.exception 4 -> !cir.ptr<!u32i>
+//CIR: %[[EXCEPTION_VALUE:.*]] = cir.const #cir.int<0> : !u32i
+//CIR: cir.store{{.*}} %[[EXCEPTION_VALUE]], %[[EXCEPTION_ADDR]] : !u32i, !cir.ptr<!u32i>
+//CIR: cir.throw %[[EXCEPTION_ADDR]] : !cir.ptr<!u32i>, @_ZTIZ15throw_enum_exprvE4Test
+//CIR: cir.unreachable
+
+//LLVM: %[[EXCEPTION_ADDR:.*]] = call ptr @__cxa_allocate_exception(i64 4)
+//LLVM: store i32 0, ptr %[[EXCEPTION_ADDR]], align 16
+//LLVM: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR]], ptr @_ZTIZ15throw_enum_exprvE4Test, ptr null)
+//LLVM: unreachable
+
+//OGCG: %[[EXCEPTION_ADDR:.*]] = call ptr @__cxa_allocate_exception(i64 4)
+//OGCG: store i32 0, ptr %[[EXCEPTION_ADDR]], align 16
+//OGCG: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR]], ptr @_ZTIZ15throw_enum_exprvE4Test, ptr null)
+//OGCG: unreachable
+
+void throw_enum_class_expr() {
+ enum class Test {
+ TestA,
+ TestB
+ };
+ throw Test::TestA;
+}
+
+//CIR: %[[EXCEPTION_ADDR:.*]] = cir.alloc.exception 4 -> !cir.ptr<!s32i>
+//CIR: %[[EXCEPTION_VALUE:.*]] = cir.const #cir.int<0> : !s32i
+//CIR: cir.store{{.*}} %[[EXCEPTION_VALUE]], %[[EXCEPTION_ADDR]] : !s32i, !cir.ptr<!s32i>
+//CIR: cir.throw %[[EXCEPTION_ADDR]] : !cir.ptr<!s32i>, @_ZTIZ21throw_enum_class_exprvE4Test
+//CIR: cir.unreachable
+
+//LLVM: %[[EXCEPTION_ADDR:.*]] = call ptr @__cxa_allocate_exception(i64 4)
+//LLVM: store i32 0, ptr %[[EXCEPTION_ADDR]], align 16
+//LLVM: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR]], ptr @_ZTIZ21throw_enum_class_exprvE4Test, ptr null)
+//LLVM: unreachable
+
+//OGCG: %[[EXCEPTION_ADDR:.*]] = call ptr @__cxa_allocate_exception(i64 4)
+//OGCG: store i32 0, ptr %[[EXCEPTION_ADDR]], align 16
+//OGCG: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR]], ptr @_ZTIZ21throw_enum_class_exprvE4Test, ptr null)
+//OGCG: unreachable
|
@llvm/pr-subscribers-clang Author: Omar Hossam (moar55) ChangesThis commit adds the RTTI support for enum in the vtable. Full diff: https://github.com/llvm/llvm-project/pull/163612.diff 2 Files Affected:
diff --git a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
index 9bb1fe1d49a25..276675cbca5f5 100644
--- a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
@@ -952,8 +952,7 @@ const char *vTableClassNameForType(const CIRGenModule &cgm, const Type *ty) {
break;
case Type::Enum:
- cgm.errorNYI("VTableClassNameForType: Enum");
- break;
+ return "_ZTVN10__cxxabiv116__enum_type_infoE";
case Type::Record: {
const CXXRecordDecl *rd =
diff --git a/clang/test/CIR/CodeGen/throws.cpp b/clang/test/CIR/CodeGen/throws.cpp
index 4255d436d4a32..f8aa965b1a4aa 100644
--- a/clang/test/CIR/CodeGen/throws.cpp
+++ b/clang/test/CIR/CodeGen/throws.cpp
@@ -144,3 +144,52 @@ void throw_complex_expr() {
// OGCG: store float 0x3FF19999A0000000, ptr %[[EXCEPTION_REAL]], align 16
// OGCG: store float 0x40019999A0000000, ptr %[[EXCEPTION_IMAG]], align 4
// OGCG: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR]], ptr @_ZTICf, ptr null)
+
+
+void throw_enum_expr() {
+ enum Test {
+ TestA,
+ TestB
+ };
+ throw Test::TestA;
+}
+
+//CIR: %[[EXCEPTION_ADDR:.*]] = cir.alloc.exception 4 -> !cir.ptr<!u32i>
+//CIR: %[[EXCEPTION_VALUE:.*]] = cir.const #cir.int<0> : !u32i
+//CIR: cir.store{{.*}} %[[EXCEPTION_VALUE]], %[[EXCEPTION_ADDR]] : !u32i, !cir.ptr<!u32i>
+//CIR: cir.throw %[[EXCEPTION_ADDR]] : !cir.ptr<!u32i>, @_ZTIZ15throw_enum_exprvE4Test
+//CIR: cir.unreachable
+
+//LLVM: %[[EXCEPTION_ADDR:.*]] = call ptr @__cxa_allocate_exception(i64 4)
+//LLVM: store i32 0, ptr %[[EXCEPTION_ADDR]], align 16
+//LLVM: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR]], ptr @_ZTIZ15throw_enum_exprvE4Test, ptr null)
+//LLVM: unreachable
+
+//OGCG: %[[EXCEPTION_ADDR:.*]] = call ptr @__cxa_allocate_exception(i64 4)
+//OGCG: store i32 0, ptr %[[EXCEPTION_ADDR]], align 16
+//OGCG: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR]], ptr @_ZTIZ15throw_enum_exprvE4Test, ptr null)
+//OGCG: unreachable
+
+void throw_enum_class_expr() {
+ enum class Test {
+ TestA,
+ TestB
+ };
+ throw Test::TestA;
+}
+
+//CIR: %[[EXCEPTION_ADDR:.*]] = cir.alloc.exception 4 -> !cir.ptr<!s32i>
+//CIR: %[[EXCEPTION_VALUE:.*]] = cir.const #cir.int<0> : !s32i
+//CIR: cir.store{{.*}} %[[EXCEPTION_VALUE]], %[[EXCEPTION_ADDR]] : !s32i, !cir.ptr<!s32i>
+//CIR: cir.throw %[[EXCEPTION_ADDR]] : !cir.ptr<!s32i>, @_ZTIZ21throw_enum_class_exprvE4Test
+//CIR: cir.unreachable
+
+//LLVM: %[[EXCEPTION_ADDR:.*]] = call ptr @__cxa_allocate_exception(i64 4)
+//LLVM: store i32 0, ptr %[[EXCEPTION_ADDR]], align 16
+//LLVM: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR]], ptr @_ZTIZ21throw_enum_class_exprvE4Test, ptr null)
+//LLVM: unreachable
+
+//OGCG: %[[EXCEPTION_ADDR:.*]] = call ptr @__cxa_allocate_exception(i64 4)
+//OGCG: store i32 0, ptr %[[EXCEPTION_ADDR]], align 16
+//OGCG: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR]], ptr @_ZTIZ21throw_enum_class_exprvE4Test, ptr null)
+//OGCG: unreachable
|
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.
Thanks for working on this
// OGCG: store float 0x3FF19999A0000000, ptr %[[EXCEPTION_REAL]], align 16 | ||
// OGCG: store float 0x40019999A0000000, ptr %[[EXCEPTION_IMAG]], align 4 | ||
// OGCG: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR]], ptr @_ZTICf, ptr null) | ||
|
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.
Please remove this extra line
clang/test/CIR/CodeGen/throws.cpp
Outdated
throw Test::TestA; | ||
} | ||
|
||
//CIR: %[[EXCEPTION_ADDR:.*]] = cir.alloc.exception 4 -> !cir.ptr<!u32i> |
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.
//CIR: %[[EXCEPTION_ADDR:.*]] = cir.alloc.exception 4 -> !cir.ptr<!u32i> | |
//CIR: %[[EXCEPTION_ADDR:.*]] = cir.alloc.exception 4 -> !cir.ptr<!u32i> |
clang/test/CIR/CodeGen/throws.cpp
Outdated
throw Test::TestA; | ||
} | ||
|
||
//CIR: %[[EXCEPTION_ADDR:.*]] = cir.alloc.exception 4 -> !cir.ptr<!s32i> |
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.
//CIR: %[[EXCEPTION_ADDR:.*]] = cir.alloc.exception 4 -> !cir.ptr<!s32i> | |
//CIR: %[[EXCEPTION_ADDR:.*]] = cir.alloc.exception 4 -> !cir.ptr<!s32i> |
clang/test/CIR/CodeGen/throws.cpp
Outdated
throw Test::TestA; | ||
} | ||
|
||
//CIR: %[[EXCEPTION_ADDR:.*]] = cir.alloc.exception 4 -> !cir.ptr<!u32i> |
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.
Please keep the same format of the test
//CIR :
-> // CIR:
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.
LGTM once @AmrDeveloper concerns are addressed!
a21a9c2
to
10e2373
Compare
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.
LGTM, Thanks!
This commit adds the RTTI support for enum in the vtable.
Issue #163601