Skip to content

Commit 531a1ab

Browse files
authored
Disable LICM for nightly UBSan testing and note in docs (#29066)
Disables LICM for nightly UBSan testing due to false positives with LICM. This is then noted in the docs for users who might want to use UBSan. [Reviewed by @benharsh]
2 parents a1ec318 + 5fa7f47 commit 531a1ab

6 files changed

Lines changed: 29 additions & 6 deletions

File tree

compiler/main/driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,7 @@ static ArgumentDescription arg_desc[] = {
14401440
{"inline-iterators", ' ', NULL, "Enable [disable] iterator inlining", "n", &fNoInlineIterators, "CHPL_DISABLE_INLINE_ITERATORS", NULL},
14411441
{"inline-iterators-yield-limit", ' ', "<limit>", "Limit number of yields permitted in inlined iterators", "I", &inline_iter_yield_limit, "CHPL_INLINE_ITER_YIELD_LIMIT", NULL},
14421442
{"live-analysis", ' ', NULL, "Enable [disable] live variable analysis", "n", &fNoLiveAnalysis, "CHPL_DISABLE_LIVE_ANALYSIS", NULL},
1443-
{"loop-invariant-code-motion", ' ', NULL, "Enable [disable] loop invariant code motion", "n", &fNoLoopInvariantCodeMotion, NULL, NULL},
1443+
{"loop-invariant-code-motion", ' ', NULL, "Enable [disable] loop invariant code motion", "n", &fNoLoopInvariantCodeMotion, "CHPL_LOOP_INVARIANT_CODE_MOTION", NULL},
14441444
{"optimize-forall-unordered-ops", ' ', NULL, "Enable [disable] optimization of foralls to unordered operations", "n", &fNoOptimizeForallUnordered, "CHPL_DISABLE_OPTIMIZE_FORALL_UNORDERED_OPS", NULL},
14451445
{"optimize-range-iteration", ' ', NULL, "Enable [disable] optimization of iteration over anonymous ranges", "n", &fNoOptimizeRangeIteration, "CHPL_DISABLE_OPTIMIZE_RANGE_ITERATION", NULL},
14461446
{"optimize-loop-iterators", ' ', NULL, "Enable [disable] optimization of iterators composed of a single loop", "n", &fNoOptimizeLoopIterators, "CHPL_DISABLE_OPTIMIZE_LOOP_ITERATORS", NULL},

doc/rst/developer/bestPractices/Sanitizers.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,12 @@ code (including internal modules).
9797
9898
chpl <program.chpl> --ccflags=-fsanitize=undefined --ldflags=-fsanitize=undefined
9999
./<program>
100+
101+
102+
.. note::
103+
104+
UBSan has been found to interact poorly with some Chapel optimizations.
105+
LICM (loop invariant code motion) in particular can result in
106+
false positives. Nightly testing with UBSan is done with LICM disabled.
107+
If you are using UBSan and seeing what looks like a false positive, try
108+
disabling LICM with ``--no-loop-invariant-code-motion``.

doc/rst/usingchapel/debugging/sanitizers.rst

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,19 @@ sanitizers. In particular:
8989
Other Sanitizers
9090
----------------
9191

92-
Currently, only AddressSanitizer is regularly tested, but the options passed to
93-
``CHPL_SANITIZE_EXE`` are passed directly to the backend compiler's
94-
``-fsanitize=`` option, so other sanitizers can be enabled. For example, to use
95-
C undefined behavior sanitizer and address sanitizer set
96-
``CHPL_SANITIZE_EXE=undefined,memory``.
92+
Currently, only AddressSanitizer and UndefinedBehaviorSanitizer are regularly
93+
tested, but the options passed to ``CHPL_SANITIZE_EXE`` are passed directly to
94+
the backend compiler's ``-fsanitize=`` option, so other sanitizers can be
95+
enabled. For example, to use C undefined behavior sanitizer and address
96+
sanitizer set ``CHPL_SANITIZE_EXE=undefined,memory``.
97+
98+
.. note::
99+
100+
``CHPL_SANITIZE_EXE=undefined`` can result in false positives due to
101+
optimizations performed by the Chapel compiler. Specifically,
102+
loop invariant code motion (LICM) can result in false positives.
103+
If you are using UBSan and seeing what looks like a false positive,
104+
try disabling LICM with ``--no-loop-invariant-code-motion``.
97105

98106

99107
.. TODO: tsan fails in the runtime: https://github.com/chapel-lang/chapel/issues/27670

test/llvm/licm/COMPOPTS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--loop-invariant-code-motion

test/optimizations/licm/COMPOPTS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--loop-invariant-code-motion

util/cron/common-ubsan.bash

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ UTIL_CRON_DIR=$(cd $(dirname ${BASH_SOURCE[0]}) ; pwd)
77
export CHPL_TARGET_MEM=cstdlib
88
export CHPL_HOST_MEM=cstdlib
99
export CHPL_SANITIZE=undefined
10+
# disable licm, since this can result in false positives
11+
# e.g.: x < max(int) && x + 2, if `x + 2` is hoisted there will be an overflow
12+
# but its harmless because the result is never used.
13+
export CHPL_LOOP_INVARIANT_CODE_MOTION=false

0 commit comments

Comments
 (0)