r345816 - [clang][CodeGen] ImplicitIntegerSignChangeSanitizer: actually ignore NOP casts.
Roman Lebedev via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 1 01:56:51 PDT 2018
Author: lebedevri
Date: Thu Nov 1 01:56:51 2018
New Revision: 345816
URL: http://llvm.org/viewvc/llvm-project?rev=345816&view=rev
Log:
[clang][CodeGen] ImplicitIntegerSignChangeSanitizer: actually ignore NOP casts.
I fully expected for that to be handled by the canonical type check,
but it clearly wasn't. Sadly, somehow it hide until now.
Reported by Eli Friedman.
Modified:
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/test/CodeGen/catch-implicit-integer-sign-changes-true-negatives.c
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=345816&r1=345815&r2=345816&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Thu Nov 1 01:56:51 2018
@@ -1127,10 +1127,9 @@ void ScalarExprEmitter::EmitIntegerSignC
// Now, we do not need to emit the check in *all* of the cases.
// We can avoid emitting it in some obvious cases where it would have been
// dropped by the opt passes (instcombine) always anyways.
- // If it's a cast between the same type, just differently-sugared. no check.
- QualType CanonSrcType = CGF.getContext().getCanonicalType(SrcType);
- QualType CanonDstType = CGF.getContext().getCanonicalType(DstType);
- if (CanonSrcType == CanonDstType)
+ // If it's a cast between effectively the same type, no check.
+ // NOTE: this is *not* equivalent to checking the canonical types.
+ if (SrcSigned == DstSigned && SrcBits == DstBits)
return;
// At least one of the values needs to have signed type.
// If both are unsigned, then obviously, neither of them can be negative.
Modified: cfe/trunk/test/CodeGen/catch-implicit-integer-sign-changes-true-negatives.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/catch-implicit-integer-sign-changes-true-negatives.c?rev=345816&r1=345815&r2=345816&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/catch-implicit-integer-sign-changes-true-negatives.c (original)
+++ cfe/trunk/test/CodeGen/catch-implicit-integer-sign-changes-true-negatives.c Thu Nov 1 01:56:51 2018
@@ -138,3 +138,15 @@ uint32_t unsigned_int_to_uint32(unsigned
uint32_t uint32_to_uint32(uint32_t src) {
return src;
}
+
+// "Transparent" Enum.
+// ========================================================================== //
+
+enum a { b = ~2147483647 };
+enum a c();
+void d(int);
+void e();
+void e() {
+ enum a f = c();
+ d(f);
+}
More information about the cfe-commits
mailing list