add support for clang plugin unit tests
MODIFY
scripts/alivecc.in
scripts/alivecc.in
@@ -13,6 +13,13 @@ else
exit -1
fi
+if [[ "$OSTYPE" == "darwin"* ]]; then
+ # Mac
+ TV_SHAREDLIB=tv.dylib
+else
+ # Linux, Cygwin/Msys, or Win32?
+ TV_SHAREDLIB=tv.so
+fi
@LLVM_BINARY_DIR@/bin/$EXE \
- -fpass-plugin=@CMAKE_BINARY_DIR@/tv/tv.so -fexperimental-new-pass-manager \
- -Xclang -load -Xclang @CMAKE_BINARY_DIR@/tv/tv.so $*
+ -fpass-plugin=@CMAKE_BINARY_DIR@/tv/$TV_SHAREDLIB -fexperimental-new-pass-manager \
+ -Xclang -load -Xclang @CMAKE_BINARY_DIR@/tv/$TV_SHAREDLIB $*

ADD
tests/clang-tv/interprocedural.cpp
+// TEST-ARGS: -O3
+// A simple test that checks whether InferFunctionAttrsPass is skipped and
+// SimplifyCFGPass is not skipped.
+
+int f(){ return 0; }
+
+// CHECK: InferFunctionAttrsPass : Skipping
+// CHECK-NOT: SimplifyCFGPass : Skipping

ADD
tests/clang-tv/issue569.cpp
+// TEST-ARGS: -O3 -mllvm -tv-tgt-unroll=2 -mllvm -tv-src-unroll=2
+void a() {
+ for (;;)
+ for (int b; b;)
+ ;
+}
+
+// Since it has 'ERROR: Precondition is always false', this CHECK is necessary
+// (otherwise this test will fail)
+// CHECK: Transformation seems to be correct

ADD
tests/clang-tv/issue579.c
+// TEST-ARGS: -O3 -mllvm -tv-tgt-unroll=2 -mllvm -tv-src-unroll=2 -mllvm -tv-smt-to=10000 -mllvm -tv-disable-undef-input -mllvm -tv-disable-poison-input
+short *d;
+
+e(int a, int b, int c) {
+ for (int f = 0; f < b; f += c)
+ a = d[c];
+}

MODIFY
tests/lit/lit/formats/alive2test.py
tests/lit/lit/formats/alive2test.py
@@ -49,9 +49,9 @@ class Alive2Test(TestFormat):
def __init__(self):
self.regex_errs = re.compile(r";\s*(ERROR:.*)")
self.regex_xfail = re.compile(r";\s*XFAIL:\s*(.*)")
- self.regex_args = re.compile(r";\s*TEST-ARGS:(.*)")
- self.regex_check = re.compile(r";\s*CHECK:(.*)")
- self.regex_check_not = re.compile(r";\s*CHECK-NOT:(.*)")
+ self.regex_args = re.compile(r"(?:;|//)\s*TEST-ARGS:(.*)")
+ self.regex_check = re.compile(r"(?:;|//)\s*CHECK:(.*)")
+ self.regex_check_not = re.compile(r"(?:;|//)\s*CHECK-NOT:(.*)")
self.regex_skip_identity = re.compile(r";\s*SKIP-IDENTITY")
self.regex_errs_out = re.compile("ERROR:.*")
@@ -63,7 +63,8 @@ class Alive2Test(TestFormat):
if not filename.startswith('.') and \
not os.path.isdir(filepath) and \
(filename.endswith('.opt') or filename.endswith('.src.ll') or
- filename.endswith('.srctgt.ll')):
+ filename.endswith('.srctgt.ll') or filename.endswith('.c') or
+ filename.endswith('.cpp')):
yield lit.Test.Test(testSuite, path_in_suite + (filename,), localConfig)
@@ -82,7 +83,16 @@ class Alive2Test(TestFormat):
if not os.path.isfile('alive-tv'):
return lit.Test.UNSUPPORTED, ''
- if not alive_tv_1 and not alive_tv_2:
+ clang_tv = test.endswith('.c') or test.endswith('.cpp')
+ if clang_tv:
+ execpath = './scripts/%s' % ("alivecc" if test.endswith('.c')
+ else "alive++")
+ # 30 seconds is too long to apply to all passes, just use the default to
+ cmd = [execpath, "-c", "-o", "/dev/null"]
+ if not os.path.isfile(execpath):
+ return lit.Test.UNSUPPORTED, ''
+
+ if not alive_tv_1 and not alive_tv_2 and not clang_tv:
cmd = ['./alive', '-smt-to:30000']
input = readFile(test)
@@ -131,6 +141,11 @@ class Alive2Test(TestFormat):
if chk_not != None and output.find(chk_not.group(1).strip()) != -1:
return lit.Test.FAIL, output
+ if clang_tv and exitCode != 0:
+ # clang tv should not exit with non-zero even if validation fails.
+ # Otherwise it will stop a build system such as `make`.
+ return lit.Test.FAIL, output
+
expect_err = self.regex_errs.search(input)
if expect_err is None and xfail is None and chk is None and chk_not is None:
# If there's no other test, correctness of the transformation should be

add support for clang plugin unit tests (#588)