about summary refs log tree commit diff
path: root/buildtools
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2016-05-03 03:10:14 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2016-05-03 03:10:14 +0000
commit286b6dace546526ad3abc24ee743a578b587db79 (patch)
treecca6deb758deb275e41dfa2a3e25fa9908debdf7 /buildtools
parent6d789bfd7fbf2f63b9fb7c34982826c8fa31db64 (diff)
downloadnetpbm-mirror-286b6dace546526ad3abc24ee743a578b587db79.tar.gz
netpbm-mirror-286b6dace546526ad3abc24ee743a578b587db79.tar.xz
netpbm-mirror-286b6dace546526ad3abc24ee743a578b587db79.zip
Add -Wno-strict-overflow
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@2742 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'buildtools')
-rwxr-xr-xbuildtools/configure.pl48
1 files changed, 43 insertions, 5 deletions
diff --git a/buildtools/configure.pl b/buildtools/configure.pl
index 9cafd019..5a7d8a33 100755
--- a/buildtools/configure.pl
+++ b/buildtools/configure.pl
@@ -1456,14 +1456,52 @@ sub gnuOptimizeOpt($) {
 
 
 
+sub wnostrictoverflowWorks($) {
+    my ($gccCommandName) = @_;
+
+    my ($cFile, $cFileName) = tempFile(".c");
+
+    print $cFile "int x;";
+    
+    my $compileCommand =
+        "$gccCommandName -c -o /dev/null -Wno-strict-overflow $cFileName";
+    print ("Doing test compile to see if -Wno-strict-overflow works: "
+           . "$compileCommand\n");
+    my $rc = system($compileCommand);
+    
+    unlink($cFileName);
+    close($cFile);
+
+    return ($rc == 0);
+}
+
+
+
 sub gnuCflags($) {
     my ($gccCommandName) = @_;
 
-    return("CFLAGS = " . gnuOptimizeOpt($gccCommandName) . " -ffast-math " .
-           " -pedantic -fno-common " . 
-           "-Wall -Wno-uninitialized -Wmissing-declarations -Wimplicit " .
-           "-Wwrite-strings -Wmissing-prototypes -Wundef " .
-           "-Wno-unknown-pragmas\n");
+    my $flags;
+
+    $flags = gnuOptimizeOpt($gccCommandName) . " -ffast-math " .
+        " -pedantic -fno-common " . 
+        "-Wall -Wno-uninitialized -Wmissing-declarations -Wimplicit " .
+        "-Wwrite-strings -Wmissing-prototypes -Wundef " .
+        "-Wno-unknown-pragmas ";
+
+    if (wnostrictoverflowWorks($gccCommandName)) {
+        # The compiler generates some optimizations based on the assumption
+        # that you wouldn't code something that can arithmetically overflow,
+        # so adding a positive value to something can only make it bigger.
+        # E.g. if (x + y > x), where y is unsigned, is a no-op.  The compiler
+        # optionally warns when it makes that assumption.  Sometimes, the
+        # compiler is able to do that optimization because of inlining, so the
+        # code per se is not ridiculous, it just becomes superfluous in
+        # context.  That means you can't code around the warning.  Ergo, we
+        # must disable the warning.
+
+        $flags .= '-Wno-strict-overflow';
+    }
+    return("CFLAGS = $flags\n");
 }