]> granicus.if.org Git - clang/commitdiff
[Diagnostics] Support -Wtype-limits for GCC compatibility
authorDavid Bolvansky <david.bolvansky@gmail.com>
Mon, 29 Apr 2019 23:24:00 +0000 (23:24 +0000)
committerDavid Bolvansky <david.bolvansky@gmail.com>
Mon, 29 Apr 2019 23:24:00 +0000 (23:24 +0000)
Summary:
GCC's  -Wtype-limits (part of -Wextra):
Warn if a comparison is always true or always false due to the limited range of the data type

Reviewers: rsmith, aaron.ballman, lebedev.ri, thakis

Reviewed By: rsmith

Subscribers: lebedev.ri, jdoerfert, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D58841

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359516 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticGroups.td
test/Sema/compare.c
test/Sema/tautological-constant-compare.c
test/Sema/tautological-constant-enum-compare.c
test/SemaCXX/compare.cpp

index d46f82f2a5282ab8a80670ac60dde3b3924250a4..e46266d3052045f2c7b859680ae2d33750935fb0 100644 (file)
@@ -485,6 +485,8 @@ def TautologicalInRangeCompare : DiagGroup<"tautological-constant-in-range-compa
                                            [TautologicalTypeLimitCompare,
                                             TautologicalUnsignedZeroCompare,
                                             TautologicalUnsignedEnumZeroCompare]>;
+// For compatibility with GCC; -Wtype-limits = -Wtautological-constant-in-range-compare
+def TypeLimits : DiagGroup<"type-limits", [TautologicalInRangeCompare]>;
 def TautologicalOutOfRangeCompare : DiagGroup<"tautological-constant-out-of-range-compare">;
 def TautologicalConstantCompare : DiagGroup<"tautological-constant-compare",
                                             [TautologicalOutOfRangeCompare]>;
index b2b486f59f8783d47af881de2b7ee9941fdfe6a0..25aa13f6ba38db0ff6287fe44f8dc2f1341111bd 100644 (file)
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare -Wtautological-constant-in-range-compare %s -Wno-unreachable-code
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare -Wtype-limits %s -Wno-unreachable-code
 
 int test(char *C) { // nothing here should warn.
   return C != ((void*)0);
index b242f35dc6cf556829df50f1084d535f23328575..4f9b43b9f8982d7fd8b362bf9899c6fc471415d7 100644 (file)
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wtautological-constant-in-range-compare -DTEST -verify -x c++ %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wtautological-type-limit-compare -DTEST -verify %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wtautological-type-limit-compare -DTEST -verify -x c++ %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wtype-limits -DTEST -verify %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wtype-limits -DTEST -verify -x c++ %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wextra -Wno-sign-compare -verify %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wextra -Wno-sign-compare -verify -x c++ %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wall -verify %s
index 99481c7adb33f793fa33939ce4c2c9d9648e0ac8..dcac2457380960eea7b8e99d3ee0ed5a63cc3db2 100644 (file)
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only -DSIGNED -Wtautological-constant-in-range-compare -verify %s
 // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED -DSILENCE -Wno-tautological-constant-compare -verify %s
 // RUN: %clang_cc1 -triple=x86_64-pc-win32 -fsyntax-only -DSIGNED -DSILENCE -Wno-tautological-constant-compare -verify %s
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED -Wtype-limits -verify %s
+// RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED -DSILENCE -Wno-type-limits -verify %s
 
 int main() {
   enum A { A_a = 2 };
index ee0fe01fd1d1db7e540aa1a55693bef8684e68b5..55b01e3dc348bfcff9608c3b265865ddc0f4f864 100644 (file)
@@ -2,6 +2,7 @@
 // on integer sizes.
 
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare -Wtautological-constant-in-range-compare -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare -Wtype-limits -std=c++11 %s
 
 int test0(long a, unsigned long b) {
   enum EnumA {A};