Recommit r246175 - Add Kaleidoscope regression tests, with a fix to make sure
the kaleidoscope 'library' functions aren't dead-stripped in release builds.
llvm-svn: 246201
GitOrigin-RevId: d76e06715056710199bb74b4582e9c343a252aeb
diff --git a/docs/tutorial/LangImpl4.rst b/docs/tutorial/LangImpl4.rst
index 702886f..92dcc3d 100644
--- a/docs/tutorial/LangImpl4.rst
+++ b/docs/tutorial/LangImpl4.rst
@@ -566,7 +566,7 @@
/// putchard - putchar that takes a double and returns 0.
extern "C" double putchard(double X) {
- putchar((char)X);
+ fputc((char)X, stderr);
return 0;
}
diff --git a/examples/Kaleidoscope/Chapter4/CMakeLists.txt b/examples/Kaleidoscope/Chapter4/CMakeLists.txt
index 44e1aee..89feed1 100644
--- a/examples/Kaleidoscope/Chapter4/CMakeLists.txt
+++ b/examples/Kaleidoscope/Chapter4/CMakeLists.txt
@@ -13,3 +13,5 @@
add_kaleidoscope_chapter(Kaleidoscope-Ch4
toy.cpp
)
+
+export_executable_symbols(Kaleidoscope-Ch4)
diff --git a/examples/Kaleidoscope/Chapter4/toy.cpp b/examples/Kaleidoscope/Chapter4/toy.cpp
index 12777ae..fe8ec17 100644
--- a/examples/Kaleidoscope/Chapter4/toy.cpp
+++ b/examples/Kaleidoscope/Chapter4/toy.cpp
@@ -631,14 +631,14 @@
//===----------------------------------------------------------------------===//
/// putchard - putchar that takes a double and returns 0.
-extern "C" double putchard(double X) {
- putchar((char)X);
+__attribute__((used)) extern "C" double putchard(double X) {
+ fputc((char)X, stderr);
return 0;
}
/// printd - printf that takes a double prints it as "%f\n", returning 0.
-extern "C" double printd(double X) {
- printf("%f\n", X);
+__attribute__((used)) extern "C" double printd(double X) {
+ fprintf(stderr, "%f\n", X);
return 0;
}
diff --git a/examples/Kaleidoscope/Chapter5/CMakeLists.txt b/examples/Kaleidoscope/Chapter5/CMakeLists.txt
index b62ed41..c0ae706 100644
--- a/examples/Kaleidoscope/Chapter5/CMakeLists.txt
+++ b/examples/Kaleidoscope/Chapter5/CMakeLists.txt
@@ -13,3 +13,5 @@
add_kaleidoscope_chapter(Kaleidoscope-Ch5
toy.cpp
)
+
+export_executable_symbols(Kaleidoscope-Ch5)
diff --git a/examples/Kaleidoscope/Chapter5/toy.cpp b/examples/Kaleidoscope/Chapter5/toy.cpp
index 83af177..4658edc 100644
--- a/examples/Kaleidoscope/Chapter5/toy.cpp
+++ b/examples/Kaleidoscope/Chapter5/toy.cpp
@@ -905,14 +905,14 @@
//===----------------------------------------------------------------------===//
/// putchard - putchar that takes a double and returns 0.
-extern "C" double putchard(double X) {
- putchar((char)X);
+__attribute__((used)) extern "C" double putchard(double X) {
+ fputc((char)X, stderr);
return 0;
}
/// printd - printf that takes a double prints it as "%f\n", returning 0.
-extern "C" double printd(double X) {
- printf("%f\n", X);
+__attribute__((used)) extern "C" double printd(double X) {
+ fprintf(stderr, "%f\n", X);
return 0;
}
diff --git a/examples/Kaleidoscope/Chapter6/CMakeLists.txt b/examples/Kaleidoscope/Chapter6/CMakeLists.txt
index 6bb2b19..49627f0 100644
--- a/examples/Kaleidoscope/Chapter6/CMakeLists.txt
+++ b/examples/Kaleidoscope/Chapter6/CMakeLists.txt
@@ -13,3 +13,5 @@
add_kaleidoscope_chapter(Kaleidoscope-Ch6
toy.cpp
)
+
+export_executable_symbols(Kaleidoscope-Ch6)
diff --git a/examples/Kaleidoscope/Chapter6/toy.cpp b/examples/Kaleidoscope/Chapter6/toy.cpp
index e1bed45..9d9914a 100644
--- a/examples/Kaleidoscope/Chapter6/toy.cpp
+++ b/examples/Kaleidoscope/Chapter6/toy.cpp
@@ -1023,14 +1023,14 @@
//===----------------------------------------------------------------------===//
/// putchard - putchar that takes a double and returns 0.
-extern "C" double putchard(double X) {
- putchar((char)X);
+__attribute__((used)) extern "C" double putchard(double X) {
+ fputc((char)X, stderr);
return 0;
}
/// printd - printf that takes a double prints it as "%f\n", returning 0.
-extern "C" double printd(double X) {
- printf("%f\n", X);
+__attribute__((used)) extern "C" double printd(double X) {
+ fprintf(stderr, "%f\n", X);
return 0;
}
diff --git a/examples/Kaleidoscope/Chapter7/CMakeLists.txt b/examples/Kaleidoscope/Chapter7/CMakeLists.txt
index 27c18cd..e67d792 100644
--- a/examples/Kaleidoscope/Chapter7/CMakeLists.txt
+++ b/examples/Kaleidoscope/Chapter7/CMakeLists.txt
@@ -13,3 +13,5 @@
add_kaleidoscope_chapter(Kaleidoscope-Ch7
toy.cpp
)
+
+export_executable_symbols(Kaleidoscope-Ch7)
diff --git a/examples/Kaleidoscope/Chapter7/toy.cpp b/examples/Kaleidoscope/Chapter7/toy.cpp
index 4558522..d61d880 100644
--- a/examples/Kaleidoscope/Chapter7/toy.cpp
+++ b/examples/Kaleidoscope/Chapter7/toy.cpp
@@ -1189,14 +1189,14 @@
//===----------------------------------------------------------------------===//
/// putchard - putchar that takes a double and returns 0.
-extern "C" double putchard(double X) {
- putchar((char)X);
+__attribute__((used)) extern "C" double putchard(double X) {
+ fputc((char)X, stderr);
return 0;
}
/// printd - printf that takes a double prints it as "%f\n", returning 0.
-extern "C" double printd(double X) {
- printf("%f\n", X);
+__attribute__((used)) extern "C" double printd(double X) {
+ fprintf(stderr, "%f\n", X);
return 0;
}
diff --git a/examples/Kaleidoscope/Chapter8/CMakeLists.txt b/examples/Kaleidoscope/Chapter8/CMakeLists.txt
index e335cb4..d9b5cc4 100644
--- a/examples/Kaleidoscope/Chapter8/CMakeLists.txt
+++ b/examples/Kaleidoscope/Chapter8/CMakeLists.txt
@@ -9,3 +9,5 @@
add_kaleidoscope_chapter(Kaleidoscope-Ch8
toy.cpp
)
+
+export_executable_symbols(Kaleidoscope-Ch8)
diff --git a/examples/Kaleidoscope/Chapter8/toy.cpp b/examples/Kaleidoscope/Chapter8/toy.cpp
index 7338c6e..5f97a15 100644
--- a/examples/Kaleidoscope/Chapter8/toy.cpp
+++ b/examples/Kaleidoscope/Chapter8/toy.cpp
@@ -1383,14 +1383,14 @@
//===----------------------------------------------------------------------===//
/// putchard - putchar that takes a double and returns 0.
-extern "C" double putchard(double X) {
- putchar((char)X);
+__attribute__((used)) extern "C" double putchard(double X) {
+ fputc((char)X, stderr);
return 0;
}
/// printd - printf that takes a double prints it as "%f\n", returning 0.
-extern "C" double printd(double X) {
- printf("%f\n", X);
+__attribute__((used)) extern "C" double printd(double X) {
+ fprintf(stderr, "%f\n", X);
return 0;
}
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 1f417c2..464a6f0 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -1,3 +1,7 @@
+if(LLVM_BUILD_EXAMPLES)
+ set(ENABLE_EXAMPLES 1)
+endif()
+
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
@@ -96,6 +100,16 @@
)
endif()
+if(LLVM_BUILD_EXAMPLES)
+ list(APPEND LLVM_TEST_DEPENDS
+ Kaleidoscope-Ch3
+ Kaleidoscope-Ch4
+ Kaleidoscope-Ch5
+ Kaleidoscope-Ch6
+ Kaleidoscope-Ch7
+ )
+endif()
+
add_lit_testsuite(check-llvm "Running the LLVM regression tests"
${CMAKE_CURRENT_BINARY_DIR}
PARAMS llvm_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
diff --git a/test/Makefile b/test/Makefile
index 558762e..9b37ced 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -146,6 +146,7 @@
@$(ECHOPATH) s=@HOST_ARCH@=$(HOST_ARCH)=g >> lit.tmp
@$(ECHOPATH) s=@HAVE_LIBZ@=$(HAVE_LIBZ)=g >> lit.tmp
@$(ECHOPATH) s=@HAVE_DIA_SDK@=0=g >> lit.tmp
+ @$(ECHOPATH) s=@ENABLE_EXAMPLES@=$(BUILD_EXAMPLES)=g >> lit.tmp
@sed -f lit.tmp $(PROJ_SRC_DIR)/lit.site.cfg.in > $@
@-rm -f lit.tmp
diff --git a/test/lit.cfg b/test/lit.cfg
index 167a81a..38a2ec2 100644
--- a/test/lit.cfg
+++ b/test/lit.cfg
@@ -258,6 +258,12 @@
r"\byaml2obj\b",
r"\byaml-bench\b",
r"\bverify-uselistorder\b",
+ r"\bKaleidoscope-Ch3\b",
+ r"\bKaleidoscope-Ch4\b",
+ r"\bKaleidoscope-Ch5\b",
+ r"\bKaleidoscope-Ch6\b",
+ r"\bKaleidoscope-Ch7\b",
+ r"\bKaleidoscope-Ch8\b",
# Handle these specially as they are strings searched
# for during testing.
r"\| \bcount\b",
diff --git a/test/lit.site.cfg.in b/test/lit.site.cfg.in
index 0b8ca65..a181037 100644
--- a/test/lit.site.cfg.in
+++ b/test/lit.site.cfg.in
@@ -35,6 +35,7 @@
config.have_zlib = "@HAVE_LIBZ@"
config.have_dia_sdk = @HAVE_DIA_SDK@
config.enable_ffi = "@LLVM_ENABLE_FFI@"
+config.test_examples = "@ENABLE_EXAMPLES@"
# Support substitution of the tools_dir with user parameters. This is
# used when we can't determine the tool dir at configuration time.