[PATCH] D42561: [PR36008] Avoid -Wsign-compare warning for enum constants in typeof expressions

Alex Lorenz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 7 12:49:07 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL324514: [PR36008] Avoid -Wsign-compare warning for enum constants in (authored by arphaman, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D42561?vs=132901&id=133281#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D42561

Files:
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/test/Sema/compare.c


Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -8955,6 +8955,16 @@
   LHS = LHS->IgnoreParenImpCasts();
   RHS = RHS->IgnoreParenImpCasts();
 
+  if (!S.getLangOpts().CPlusPlus) {
+    // Avoid warning about comparison of integers with different signs when
+    // RHS/LHS has a `typeof(E)` type whose sign is different from the sign of
+    // the type of `E`.
+    if (const auto *TET = dyn_cast<TypeOfExprType>(LHS->getType()))
+      LHS = TET->getUnderlyingExpr()->IgnoreParenImpCasts();
+    if (const auto *TET = dyn_cast<TypeOfExprType>(RHS->getType()))
+      RHS = TET->getUnderlyingExpr()->IgnoreParenImpCasts();
+  }
+
   // Check to see if one of the (unmodified) operands is of different
   // signedness.
   Expr *signedOperand, *unsignedOperand;
Index: cfe/trunk/test/Sema/compare.c
===================================================================
--- cfe/trunk/test/Sema/compare.c
+++ cfe/trunk/test/Sema/compare.c
@@ -391,3 +391,16 @@
 void test12(unsigned a) {
   if (0 && -1 > a) { }
 }
+
+// PR36008
+
+enum PR36008EnumTest {
+  kPR36008Value = 0,
+};
+
+void pr36008(enum PR36008EnumTest lhs) {
+  __typeof__(lhs) x = lhs;
+  __typeof__(kPR36008Value) y = (kPR36008Value);
+  if (x == y) x = y; // no warning
+  if (y == x) y = x; // no warning
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42561.133281.patch
Type: text/x-patch
Size: 1420 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180207/bdc0afae/attachment.bin>


More information about the llvm-commits mailing list