From 1bb9aea56bdbac6fa8cb28d18a0b6c9879bee12b Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Thu, 1 Nov 2018 08:56:51 +0000 Subject: [PATCH] [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. llvm-svn: 345816 --- clang/lib/CodeGen/CGExprScalar.cpp | 7 +++---- .../catch-implicit-integer-sign-changes-true-negatives.c | 12 ++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index ef2999a..0b9a0a4 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -1127,10 +1127,9 @@ void ScalarExprEmitter::EmitIntegerSignChangeCheck(Value *Src, QualType SrcType, // 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. diff --git a/clang/test/CodeGen/catch-implicit-integer-sign-changes-true-negatives.c b/clang/test/CodeGen/catch-implicit-integer-sign-changes-true-negatives.c index 3798ccc..b847344 100644 --- a/clang/test/CodeGen/catch-implicit-integer-sign-changes-true-negatives.c +++ b/clang/test/CodeGen/catch-implicit-integer-sign-changes-true-negatives.c @@ -138,3 +138,15 @@ uint32_t unsigned_int_to_uint32(unsigned int src) { 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); +} -- 2.7.4