-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[CodeGen][CFI] Generalize transparent union in args of args of functions #158194
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
base: users/vitalybuka/spr/main.codegencfi-generalize-transparent-union-in-args-of-args-of-functions
Are you sure you want to change the base?
Conversation
Created using spr 1.3.6
|
@llvm/pr-subscribers-clang Author: Vitaly Buka (vitalybuka) ChangesAccording GCC documentation transparent union C++ ignores attribute. Full diff: https://github.com/llvm/llvm-project/pull/158194.diff 5 Files Affected:
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 46dbd85665e5d..44441df5ca6d8 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2352,8 +2352,8 @@ static QualType GeneralizeTransparentUnion(QualType Ty) {
return Ty;
}
-static QualType GeneralizeTransparentUnion(QualType Ty) {
-}
+static QualType GeneralizeFunctionType(ASTContext &Ctx, QualType Ty,
+ bool GeneralizePointers);
// Generalize pointer types to a void pointer with the qualifiers of the
// originally pointed-to type, e.g. 'const char *' and 'char * const *'
@@ -2363,12 +2363,19 @@ static QualType GeneralizeType(ASTContext &Ctx, QualType Ty,
bool GeneralizePointers) {
Ty = GeneralizeTransparentUnion(Ty);
- if (!GeneralizePointers || !Ty->isPointerType())
+ if (!Ty->isPointerType())
+ return Ty;
+
+ QualType PTy = Ty->getPointeeType();
+ if (PTy->getAs<FunctionProtoType>() || PTy->getAs<FunctionNoProtoType>())
+ Ty = Ctx.getPointerType(
+ GeneralizeFunctionType(Ctx, PTy, GeneralizePointers));
+
+ if (!GeneralizePointers)
return Ty;
return Ctx.getPointerType(
- QualType(Ctx.VoidTy)
- .withCVRQualifiers(Ty->getPointeeType().getCVRQualifiers()));
+ QualType(Ctx.VoidTy).withCVRQualifiers(PTy.getCVRQualifiers()));
}
// Apply type generalization to a FunctionType's return and argument types
diff --git a/clang/test/CodeGen/cfi-icall-generalize.c b/clang/test/CodeGen/cfi-icall-generalize.c
index 5359134805198..6659d76fbbbb2 100644
--- a/clang/test/CodeGen/cfi-icall-generalize.c
+++ b/clang/test/CodeGen/cfi-icall-generalize.c
@@ -30,5 +30,5 @@ void uni(void (*fn)(union Union), union Union arg1) {
// CHECK: [[TYPE]] = !{i64 0, !"_ZTSFPPiPKcPS2_E"}
// CHECK: [[TYPE_GENERALIZED]] = !{i64 0, !"_ZTSFPvPKvS_E.generalized"}
-// CHECK: [[TYPE2]] = !{i64 0, !"_ZTSFvPFv5UnionEPcE"}
+// CHECK: [[TYPE2]] = !{i64 0, !"_ZTSFvPFvPcES_E"}
// CHECK: [[TYPE2_GENERALIZED]] = !{i64 0, !"_ZTSFvPvS_E.generalized"}
diff --git a/clang/test/CodeGen/cfi-icall-normalize2.c b/clang/test/CodeGen/cfi-icall-normalize2.c
index b9d9af7c8a47b..49b279c04fd56 100644
--- a/clang/test/CodeGen/cfi-icall-normalize2.c
+++ b/clang/test/CodeGen/cfi-icall-normalize2.c
@@ -39,4 +39,4 @@ void uni(void (*fn)(union Union), union Union arg1) {
// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvPFvu3i32ES_E.normalized"}
// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvPFvu3i32S_ES_S_E.normalized"}
// CHECK: ![[TYPE3]] = !{i64 0, !"_ZTSFvPFvu3i32S_S_ES_S_S_E.normalized"}
-// CHECK: ![[TYPE4]] = !{i64 0, !"_ZTSFvPFv5UnionEPu2i8E.normalized"}
+// CHECK: ![[TYPE4]] = !{i64 0, !"_ZTSFvPFvPu2i8ES0_E.normalized"}
diff --git a/clang/test/CodeGen/kcfi-generalize.c b/clang/test/CodeGen/kcfi-generalize.c
index 24e054549d527..91f2be7b74818 100644
--- a/clang/test/CodeGen/kcfi-generalize.c
+++ b/clang/test/CodeGen/kcfi-generalize.c
@@ -44,5 +44,5 @@ void uni(void (*fn)(union Union), union Union arg1) {
// UNGENERALIZED: [[TYPE3]] = !{i32 874141567}
// GENERALIZED: [[TYPE3]] = !{i32 954385378}
-// UNGENERALIZED: [[TYPE2]] = !{i32 -1619636625}
+// UNGENERALIZED: [[TYPE2]] = !{i32 -1954865805}
// GENERALIZED: [[TYPE2]] = !{i32 -125078496}
\ No newline at end of file
diff --git a/clang/test/CodeGen/kcfi-normalize.c b/clang/test/CodeGen/kcfi-normalize.c
index 08f5249b6d6c3..532959a7d30fd 100644
--- a/clang/test/CodeGen/kcfi-normalize.c
+++ b/clang/test/CodeGen/kcfi-normalize.c
@@ -45,5 +45,5 @@ void uni(void (*fn)(union Union), union Union arg1) {
// CHECK: ![[TYPE1]] = !{i32 -1143117868}
// CHECK: ![[TYPE2]] = !{i32 -460921415}
// CHECK: ![[TYPE3]] = !{i32 -333839615}
-// C: ![[TYPE4]] = !{i32 -650530463}
+// C: ![[TYPE4]] = !{i32 1186327125}
// CPP: ![[TYPE4]] = !{i32 1766237188}
\ No newline at end of file
|
|
@llvm/pr-subscribers-clang-codegen Author: Vitaly Buka (vitalybuka) ChangesAccording GCC documentation transparent union C++ ignores attribute. Full diff: https://github.com/llvm/llvm-project/pull/158194.diff 5 Files Affected:
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 46dbd85665e5d..44441df5ca6d8 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2352,8 +2352,8 @@ static QualType GeneralizeTransparentUnion(QualType Ty) {
return Ty;
}
-static QualType GeneralizeTransparentUnion(QualType Ty) {
-}
+static QualType GeneralizeFunctionType(ASTContext &Ctx, QualType Ty,
+ bool GeneralizePointers);
// Generalize pointer types to a void pointer with the qualifiers of the
// originally pointed-to type, e.g. 'const char *' and 'char * const *'
@@ -2363,12 +2363,19 @@ static QualType GeneralizeType(ASTContext &Ctx, QualType Ty,
bool GeneralizePointers) {
Ty = GeneralizeTransparentUnion(Ty);
- if (!GeneralizePointers || !Ty->isPointerType())
+ if (!Ty->isPointerType())
+ return Ty;
+
+ QualType PTy = Ty->getPointeeType();
+ if (PTy->getAs<FunctionProtoType>() || PTy->getAs<FunctionNoProtoType>())
+ Ty = Ctx.getPointerType(
+ GeneralizeFunctionType(Ctx, PTy, GeneralizePointers));
+
+ if (!GeneralizePointers)
return Ty;
return Ctx.getPointerType(
- QualType(Ctx.VoidTy)
- .withCVRQualifiers(Ty->getPointeeType().getCVRQualifiers()));
+ QualType(Ctx.VoidTy).withCVRQualifiers(PTy.getCVRQualifiers()));
}
// Apply type generalization to a FunctionType's return and argument types
diff --git a/clang/test/CodeGen/cfi-icall-generalize.c b/clang/test/CodeGen/cfi-icall-generalize.c
index 5359134805198..6659d76fbbbb2 100644
--- a/clang/test/CodeGen/cfi-icall-generalize.c
+++ b/clang/test/CodeGen/cfi-icall-generalize.c
@@ -30,5 +30,5 @@ void uni(void (*fn)(union Union), union Union arg1) {
// CHECK: [[TYPE]] = !{i64 0, !"_ZTSFPPiPKcPS2_E"}
// CHECK: [[TYPE_GENERALIZED]] = !{i64 0, !"_ZTSFPvPKvS_E.generalized"}
-// CHECK: [[TYPE2]] = !{i64 0, !"_ZTSFvPFv5UnionEPcE"}
+// CHECK: [[TYPE2]] = !{i64 0, !"_ZTSFvPFvPcES_E"}
// CHECK: [[TYPE2_GENERALIZED]] = !{i64 0, !"_ZTSFvPvS_E.generalized"}
diff --git a/clang/test/CodeGen/cfi-icall-normalize2.c b/clang/test/CodeGen/cfi-icall-normalize2.c
index b9d9af7c8a47b..49b279c04fd56 100644
--- a/clang/test/CodeGen/cfi-icall-normalize2.c
+++ b/clang/test/CodeGen/cfi-icall-normalize2.c
@@ -39,4 +39,4 @@ void uni(void (*fn)(union Union), union Union arg1) {
// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvPFvu3i32ES_E.normalized"}
// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvPFvu3i32S_ES_S_E.normalized"}
// CHECK: ![[TYPE3]] = !{i64 0, !"_ZTSFvPFvu3i32S_S_ES_S_S_E.normalized"}
-// CHECK: ![[TYPE4]] = !{i64 0, !"_ZTSFvPFv5UnionEPu2i8E.normalized"}
+// CHECK: ![[TYPE4]] = !{i64 0, !"_ZTSFvPFvPu2i8ES0_E.normalized"}
diff --git a/clang/test/CodeGen/kcfi-generalize.c b/clang/test/CodeGen/kcfi-generalize.c
index 24e054549d527..91f2be7b74818 100644
--- a/clang/test/CodeGen/kcfi-generalize.c
+++ b/clang/test/CodeGen/kcfi-generalize.c
@@ -44,5 +44,5 @@ void uni(void (*fn)(union Union), union Union arg1) {
// UNGENERALIZED: [[TYPE3]] = !{i32 874141567}
// GENERALIZED: [[TYPE3]] = !{i32 954385378}
-// UNGENERALIZED: [[TYPE2]] = !{i32 -1619636625}
+// UNGENERALIZED: [[TYPE2]] = !{i32 -1954865805}
// GENERALIZED: [[TYPE2]] = !{i32 -125078496}
\ No newline at end of file
diff --git a/clang/test/CodeGen/kcfi-normalize.c b/clang/test/CodeGen/kcfi-normalize.c
index 08f5249b6d6c3..532959a7d30fd 100644
--- a/clang/test/CodeGen/kcfi-normalize.c
+++ b/clang/test/CodeGen/kcfi-normalize.c
@@ -45,5 +45,5 @@ void uni(void (*fn)(union Union), union Union arg1) {
// CHECK: ![[TYPE1]] = !{i32 -1143117868}
// CHECK: ![[TYPE2]] = !{i32 -460921415}
// CHECK: ![[TYPE3]] = !{i32 -333839615}
-// C: ![[TYPE4]] = !{i32 -650530463}
+// C: ![[TYPE4]] = !{i32 1186327125}
// CPP: ![[TYPE4]] = !{i32 1766237188}
\ No newline at end of file
|
| return Ty; | ||
|
|
||
| QualType PTy = Ty->getPointeeType(); | ||
| if (PTy->getAs<FunctionProtoType>() || PTy->getAs<FunctionNoProtoType>()) |
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.
I guess this is not the only way you can end up with a function type. E.g. pointer to pointer to function, reference to pointer to function, etc.
What do you think about doing this in the mangler? E.g. add a call to a hook near the top of void CXXNameMangler::mangleType(QualType T) and supply a hook that does the transparent_union generalization from 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.
Mangler is too late, if we have pointer generalization, it should apply to pointers form transparent union
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.
The hook could also do the pointer generalization, no?
According GCC documentation transparent union
calling convention is the same as the type of the
first member of the union.
C++ ignores attribute.
Follow up to #158193.