Re: [PATCH] D22871: Fix incorrect -Wtautological-constant-out-of-range warnings with enums

2016-08-25 Thread Ismail Badawi via cfe-commits
ibadawi abandoned this revision.
ibadawi added a comment.

Abandoning for now -- might submit another patch later according to new 
discussion on https://llvm.org/bugs/show_bug.cgi?id=16154


https://reviews.llvm.org/D22871



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D22871: Fix incorrect -Wtautological-constant-out-of-range warnings with enums

2016-07-27 Thread Ismail Badawi via cfe-commits
ibadawi created this revision.
ibadawi added reviewers: majnemer, rjmccall.
ibadawi added a subscriber: cfe-commits.

This is a proposed fix for bug 16154 
(https://llvm.org/bugs/show_bug.cgi?id=16154) -- it was tentatively fixed in 
r183084 but had the fix was backed out in r183575 because the approach taken 
wrongly affected the behavior or other warnings.

https://reviews.llvm.org/D22871

Files:
  lib/Sema/SemaChecking.cpp
  test/Sema/outof-range-constant-compare.c

Index: test/Sema/outof-range-constant-compare.c
===
--- test/Sema/outof-range-constant-compare.c
+++ test/Sema/outof-range-constant-compare.c
@@ -147,3 +147,15 @@
 
 return 1;
 }
+
+typedef enum {
+  alpha = 0,
+  bravo,
+  charlie,
+  delta,
+  echo
+} named_t;
+
+static int bar(named_t foo) {
+  return foo > 42;
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -7075,6 +7075,12 @@
 return IntRange(C.getIntWidth(QualType(T, 0)), BT->isUnsignedInteger());
   }
 
+  /// Returns the "target" range of a given integral type.
+  static IntRange forTargetOfType(ASTContext &C, QualType T) {
+return forTargetOfCanonicalType(C,
+
T->getCanonicalTypeInternal().getTypePtr());
+  }
+
   /// Returns the "target" range of a canonical integral type, i.e.
   /// the range of values expressible in the type.
   ///
@@ -7492,7 +7498,10 @@
   QualType OtherT = Other->getType();
   if (const auto *AT = OtherT->getAs())
 OtherT = AT->getValueType();
-  IntRange OtherRange = IntRange::forValueOfType(S.Context, OtherT);
+  IntRange OtherRange = S.getLangOpts().CPlusPlus
+? IntRange::forValueOfType(S.Context, OtherT)
+: IntRange::forTargetOfType(S.Context, OtherT);
+
   unsigned OtherWidth = OtherRange.Width;
 
   bool OtherIsBooleanType = Other->isKnownToHaveBooleanValue();


Index: test/Sema/outof-range-constant-compare.c
===
--- test/Sema/outof-range-constant-compare.c
+++ test/Sema/outof-range-constant-compare.c
@@ -147,3 +147,15 @@
 
 return 1;
 }
+
+typedef enum {
+  alpha = 0,
+  bravo,
+  charlie,
+  delta,
+  echo
+} named_t;
+
+static int bar(named_t foo) {
+  return foo > 42;
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -7075,6 +7075,12 @@
 return IntRange(C.getIntWidth(QualType(T, 0)), BT->isUnsignedInteger());
   }
 
+  /// Returns the "target" range of a given integral type.
+  static IntRange forTargetOfType(ASTContext &C, QualType T) {
+return forTargetOfCanonicalType(C,
+T->getCanonicalTypeInternal().getTypePtr());
+  }
+
   /// Returns the "target" range of a canonical integral type, i.e.
   /// the range of values expressible in the type.
   ///
@@ -7492,7 +7498,10 @@
   QualType OtherT = Other->getType();
   if (const auto *AT = OtherT->getAs())
 OtherT = AT->getValueType();
-  IntRange OtherRange = IntRange::forValueOfType(S.Context, OtherT);
+  IntRange OtherRange = S.getLangOpts().CPlusPlus
+? IntRange::forValueOfType(S.Context, OtherT)
+: IntRange::forTargetOfType(S.Context, OtherT);
+
   unsigned OtherWidth = OtherRange.Width;
 
   bool OtherIsBooleanType = Other->isKnownToHaveBooleanValue();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22871: Fix incorrect -Wtautological-constant-out-of-range warnings with enums

2016-07-27 Thread Ismail Badawi via cfe-commits
ibadawi updated this revision to Diff 65763.
ibadawi added a comment.

Remove extra blank line added by accident


https://reviews.llvm.org/D22871

Files:
  lib/Sema/SemaChecking.cpp

Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -7075,6 +7075,12 @@
 return IntRange(C.getIntWidth(QualType(T, 0)), BT->isUnsignedInteger());
   }
 
+  /// Returns the "target" range of a given integral type.
+  static IntRange forTargetOfType(ASTContext &C, QualType T) {
+return forTargetOfCanonicalType(C,
+
T->getCanonicalTypeInternal().getTypePtr());
+  }
+
   /// Returns the "target" range of a canonical integral type, i.e.
   /// the range of values expressible in the type.
   ///
@@ -7492,7 +7498,9 @@
   QualType OtherT = Other->getType();
   if (const auto *AT = OtherT->getAs())
 OtherT = AT->getValueType();
-  IntRange OtherRange = IntRange::forValueOfType(S.Context, OtherT);
+  IntRange OtherRange = S.getLangOpts().CPlusPlus
+? IntRange::forValueOfType(S.Context, OtherT)
+: IntRange::forTargetOfType(S.Context, OtherT);
   unsigned OtherWidth = OtherRange.Width;
 
   bool OtherIsBooleanType = Other->isKnownToHaveBooleanValue();


Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -7075,6 +7075,12 @@
 return IntRange(C.getIntWidth(QualType(T, 0)), BT->isUnsignedInteger());
   }
 
+  /// Returns the "target" range of a given integral type.
+  static IntRange forTargetOfType(ASTContext &C, QualType T) {
+return forTargetOfCanonicalType(C,
+T->getCanonicalTypeInternal().getTypePtr());
+  }
+
   /// Returns the "target" range of a canonical integral type, i.e.
   /// the range of values expressible in the type.
   ///
@@ -7492,7 +7498,9 @@
   QualType OtherT = Other->getType();
   if (const auto *AT = OtherT->getAs())
 OtherT = AT->getValueType();
-  IntRange OtherRange = IntRange::forValueOfType(S.Context, OtherT);
+  IntRange OtherRange = S.getLangOpts().CPlusPlus
+? IntRange::forValueOfType(S.Context, OtherT)
+: IntRange::forTargetOfType(S.Context, OtherT);
   unsigned OtherWidth = OtherRange.Width;
 
   bool OtherIsBooleanType = Other->isKnownToHaveBooleanValue();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22871: Fix incorrect -Wtautological-constant-out-of-range warnings with enums

2016-07-27 Thread Ismail Badawi via cfe-commits
ibadawi updated this revision to Diff 65765.
ibadawi added a comment.

Restore the test lost in patch #2. Really sorry for the noise...


https://reviews.llvm.org/D22871

Files:
  lib/Sema/SemaChecking.cpp
  test/Sema/outof-range-constant-compare.c

Index: test/Sema/outof-range-constant-compare.c
===
--- test/Sema/outof-range-constant-compare.c
+++ test/Sema/outof-range-constant-compare.c
@@ -147,3 +147,15 @@
 
 return 1;
 }
+
+typedef enum {
+  alpha = 0,
+  bravo,
+  charlie,
+  delta,
+  echo
+} named_t;
+
+static int bar(named_t foo) {
+  return foo > 42;
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -7075,6 +7075,12 @@
 return IntRange(C.getIntWidth(QualType(T, 0)), BT->isUnsignedInteger());
   }
 
+  /// Returns the "target" range of a given integral type.
+  static IntRange forTargetOfType(ASTContext &C, QualType T) {
+return forTargetOfCanonicalType(C,
+
T->getCanonicalTypeInternal().getTypePtr());
+  }
+
   /// Returns the "target" range of a canonical integral type, i.e.
   /// the range of values expressible in the type.
   ///
@@ -7492,7 +7498,9 @@
   QualType OtherT = Other->getType();
   if (const auto *AT = OtherT->getAs())
 OtherT = AT->getValueType();
-  IntRange OtherRange = IntRange::forValueOfType(S.Context, OtherT);
+  IntRange OtherRange = S.getLangOpts().CPlusPlus
+? IntRange::forValueOfType(S.Context, OtherT)
+: IntRange::forTargetOfType(S.Context, OtherT);
   unsigned OtherWidth = OtherRange.Width;
 
   bool OtherIsBooleanType = Other->isKnownToHaveBooleanValue();


Index: test/Sema/outof-range-constant-compare.c
===
--- test/Sema/outof-range-constant-compare.c
+++ test/Sema/outof-range-constant-compare.c
@@ -147,3 +147,15 @@
 
 return 1;
 }
+
+typedef enum {
+  alpha = 0,
+  bravo,
+  charlie,
+  delta,
+  echo
+} named_t;
+
+static int bar(named_t foo) {
+  return foo > 42;
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -7075,6 +7075,12 @@
 return IntRange(C.getIntWidth(QualType(T, 0)), BT->isUnsignedInteger());
   }
 
+  /// Returns the "target" range of a given integral type.
+  static IntRange forTargetOfType(ASTContext &C, QualType T) {
+return forTargetOfCanonicalType(C,
+T->getCanonicalTypeInternal().getTypePtr());
+  }
+
   /// Returns the "target" range of a canonical integral type, i.e.
   /// the range of values expressible in the type.
   ///
@@ -7492,7 +7498,9 @@
   QualType OtherT = Other->getType();
   if (const auto *AT = OtherT->getAs())
 OtherT = AT->getValueType();
-  IntRange OtherRange = IntRange::forValueOfType(S.Context, OtherT);
+  IntRange OtherRange = S.getLangOpts().CPlusPlus
+? IntRange::forValueOfType(S.Context, OtherT)
+: IntRange::forTargetOfType(S.Context, OtherT);
   unsigned OtherWidth = OtherRange.Width;
 
   bool OtherIsBooleanType = Other->isKnownToHaveBooleanValue();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits