From 8f18e12ce5db3a06ba39b3821bdec955ab18fa12 Mon Sep 17 00:00:00 2001
From: Raymond Toy <toy.raymond@gmail.com>
Date: Fri, 5 Feb 2021 05:14:29 +0000
Subject: [PATCH] Fix #101:  Add -ftrapping-math to clang compiler options

Because lisp runs with FP traps enabled, we want the C code to honor
that.  Hence add -ftrapping-math.

Also cleaned up the options, replacing -march=pentium4 and
-mtune=generic with just -mtune=pentiume4.  Replace -mfpmath=sse (not
sure what that does) with -msse2.

Finally, update CI to do a clang build so we can verify this actually
works.
---
 .gitlab-ci.yml                  | 38 +++++++++++++++++++++++++++------
 src/lisp/Config.x86_linux_clang |  6 +++++-
 2 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 286ff0392..48a8d59c1 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -7,6 +7,7 @@ stages:
   - install
   - build
   - test
+  - ansi-test
   - benchmark
 
 cache:
@@ -41,7 +42,7 @@ linux:build:
     #- bin/create-target.sh xcross x86_linux_clang
     #- bin/cross-build-world.sh -crl -B boot-2020-04-1 xtarget xcross src/tools/cross-scripts/cross-x86-x86.lisp snapshot/bin/lisp
     # Regular build using the cross-compiled result or snapshot
-    - bin/build.sh $bootstrap -R -C "" -o snapshot/bin/lisp
+    - bin/build.sh $bootstrap -R -C "x86_linux_clang" -o snapshot/bin/lisp
     - bin/make-dist.sh -I dist linux-4
 
 linux:test:
@@ -56,15 +57,28 @@ linux:test:
     # Needs artifacts from build (dist/)
     - job: linux:build
       artifacts: true
+  script:
+    - bin/run-tests.sh -l dist/bin/lisp 2>&1 | tee test.log
+
+linux:ansi-test:
+  stage: ansi-test
+  tags:
+    - linux
+  artifacts:
+    paths:
+      - ansi-test/test.out
+  needs:
+    # Needs artifacts from build (dist/)
+    - job: linux:build
+      artifacts: true
   before_script:
     - git clone https://gitlab.common-lisp.net/cmucl/ansi-test.git
     - (cd ansi-test; git checkout rtoy-cmucl-expected-failures)
   script:
-    - bin/run-tests.sh -l dist/bin/lisp 2>&1 | tee test.log
     - cd ansi-test
     - make LISP="../dist/bin/lisp -batch -noinit -nositeinit"
     - grep 'No unexpected \(successes\|failures\)' test.out
-
+    
 linux:benchmark:
   stage: benchmark
   tags:
@@ -121,21 +135,33 @@ osx:test:
     - osx
   artifacts:
     paths:
-      - ansi-test/test.out
       - test.log
   needs:
     # Needs artifacts from build (dist/)
     - job: osx:build
       artifacts: true
+  script:
+    - bin/run-tests.sh -l dist/bin/lisp 2>&1 | tee test.log
+
+osx:ansi-test:
+  stage: ansi-test
+  tags:
+    - osx
+  artifacts:
+    paths:
+      - ansi-test/test.out
+  needs:
+    # Needs artifacts from build (dist/)
+    - job: osx:build
+      artifacts: true
   before_script:
     - git clone https://gitlab.common-lisp.net/cmucl/ansi-test.git
     - (cd ansi-test; git checkout rtoy-cmucl-expected-failures)
   script:
-    - bin/run-tests.sh -l dist/bin/lisp 2>&1 | tee test.log
     - cd ansi-test
     - make LISP="../dist/bin/lisp -batch -noinit -nositeinit"
     - grep 'No unexpected \(successes\|failures\)' test.out 
-
+  
 osx:benchmark:
   stage: benchmark
   tags:
diff --git a/src/lisp/Config.x86_linux_clang b/src/lisp/Config.x86_linux_clang
index df4708222..c534e868b 100644
--- a/src/lisp/Config.x86_linux_clang
+++ b/src/lisp/Config.x86_linux_clang
@@ -4,7 +4,11 @@ include Config.x86_common
 CC = clang
 CPPFLAGS += -m32 -D__NO_CTYPE -D_GNU_SOURCE
 CFLAGS += $(COPT)
-CFLAGS += -march=pentium4 -mfpmath=sse -mtune=generic
+
+# Allow sse2 instructions (-msse2); and tune for pentium4
+# (-mtune=pentium4), the first chip to have sse2; and finally generate
+# code assuming instructions can trap (-ftrapping-math).
+CFLAGS += -msse2 -mtune=pentium4 -ftrapping-math
 
 UNDEFSYMPATTERN = -Xlinker -u -Xlinker &
 ASSEM_SRC +=  linux-stubs.S
-- 
GitLab