llvm-project/clang/lib
Chandler Carruth c41c8b3a4a Fix the warning for divide by zero to be a bit more robust. ;]
Previously, it only ever fired for zeros which formed null pointers.
Now, hilariously, in C++98 this was almost anything. Including tricks
like warning on the divisor in this code:

typedef char c3[3];
size_t f(c3* ptr) {
  return (sizeof(ptr) / sizeof(*ptr)) / (size_t)(!(sizeof(ptr) % sizeof(*ptr)));
}

Why the RHS of the outer divide is a null pointer constant is a sordid
tale of sorrow. Anyways, the committee fixed this for C++11 and onward
as part of core isssue 903, and Richard recently implemented this fix
causing the warning to go away here (and elsewhere).

This patch restores the warning here and adds it for numerous other
somewhat obvious gaffes:

int g(int x) {
  return x / (int)(0.0);
}

The patch is essentially just using the full power of our constant
folding in Clang to produce the warning, but insisting that it must fold
to an *integer* which is zero so that we don't get false positives
anywhere.

llvm-svn: 183970
2013-06-14 08:57:18 +00:00
..
ARCMigrate Modernize some low-hanging PathV1 uses. 2013-06-13 14:26:04 +00:00
AST Emit initializers for static-storage-duration temporaries as constants where 2013-06-14 03:07:01 +00:00
ASTMatchers Reduce the number of symbols on the object file. 2013-06-11 18:51:07 +00:00
Analysis [analyzer; new edges] Simplify edges in a C++11 for-range loop. 2013-06-06 21:53:45 +00:00
Basic cleanup (address some more review comments for r183474): 2013-06-10 21:36:55 +00:00
CodeGen Emit initializers for static-storage-duration temporaries as constants where 2013-06-14 03:07:01 +00:00
Driver Remove implicit fallthrough from AArch64 to Mips in lib selection 2013-06-13 22:54:55 +00:00
Edit [objcmt] Fix a mishandled conversion to objc directory literal. 2013-04-06 01:13:17 +00:00
Format Preserve newlines before block comments in static initializers. 2013-06-12 19:04:12 +00:00
Frontend Don't depend on the transitive inclusion of PathV1.h. 2013-06-13 21:09:29 +00:00
FrontendTool <rdar://problem/13509689> Introduce -module-file-info option that provides information about a particular module file. 2013-03-27 16:47:18 +00:00
Headers Even in a modules world, people will depend on the weird xmmintrin.h -> emmintrin.h forwarding. 2013-06-07 22:49:44 +00:00
Lex Introducing -Wheader-guard, a warning that checks header guards actually work 2013-06-12 21:20:57 +00:00
Parse Add -Wdeprecated warnings and fixits for things deprecated in C++11: 2013-06-13 02:02:51 +00:00
Rewrite Port HTMLDiagnostics to PathV2. No intended functionality change. 2013-06-12 18:13:05 +00:00
Sema Fix the warning for divide by zero to be a bit more robust. ;] 2013-06-14 08:57:18 +00:00
Serialization PR12086, PR15117 2013-06-12 22:31:48 +00:00
StaticAnalyzer Use the sys::ExecuteAndWait that takes StringRefs. 2013-06-13 20:08:52 +00:00
Tooling Include Path.h instead of PathV2.h. 2013-06-11 22:15:02 +00:00
CMakeLists.txt Turn CLANG_ENABLE_{ARCMT,REWRITER,STATIC_ANALYZER} into proper options so that 2013-05-29 21:09:18 +00:00
Makefile Dont use/link ARCMT, StaticAnalyzer and Rewriter to clang when the user 2012-12-13 16:09:42 +00:00