summaryrefslogtreecommitdiffstats
path: root/tools/llvm-c-test
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2015-03-23 12:10:34 -0700
committerStephen Hines <srhines@google.com>2015-03-23 12:10:34 -0700
commitebe69fe11e48d322045d5949c83283927a0d790b (patch)
treec92f1907a6b8006628a4b01615f38264d29834ea /tools/llvm-c-test
parentb7d2e72b02a4cb8034f32f8247a2558d2434e121 (diff)
downloadexternal_llvm-ebe69fe11e48d322045d5949c83283927a0d790b.zip
external_llvm-ebe69fe11e48d322045d5949c83283927a0d790b.tar.gz
external_llvm-ebe69fe11e48d322045d5949c83283927a0d790b.tar.bz2
Update aosp/master LLVM for rebase to r230699.
Change-Id: I2b5be30509658cb8266be782de0ab24f9099f9b9
Diffstat (limited to 'tools/llvm-c-test')
-rw-r--r--tools/llvm-c-test/Android.mk1
-rw-r--r--tools/llvm-c-test/CMakeLists.txt25
-rw-r--r--tools/llvm-c-test/llvm-c-test.h4
-rw-r--r--tools/llvm-c-test/main.c4
-rw-r--r--tools/llvm-c-test/metadata.c43
5 files changed, 74 insertions, 3 deletions
diff --git a/tools/llvm-c-test/Android.mk b/tools/llvm-c-test/Android.mk
index 3ab8830..6b978c0 100644
--- a/tools/llvm-c-test/Android.mk
+++ b/tools/llvm-c-test/Android.mk
@@ -13,6 +13,7 @@ llvm_c_test_SRC_FILES := \
helpers.c \
include-all.c \
main.c \
+ metadata.c \
module.c \
object.c \
targets.c \
diff --git a/tools/llvm-c-test/CMakeLists.txt b/tools/llvm-c-test/CMakeLists.txt
index 989678b..f22dffb 100644
--- a/tools/llvm-c-test/CMakeLists.txt
+++ b/tools/llvm-c-test/CMakeLists.txt
@@ -7,7 +7,26 @@ set(LLVM_LINK_COMPONENTS
Target
)
-if(TARGET LLVM)
+# We should only have llvm-c-test use libLLVM if libLLVM is built with the
+# default list of components. Using libLLVM with custom components can result in
+# build failures.
+
+set (USE_LLVM_DYLIB FALSE)
+
+if (TARGET LLVM)
+ set (USE_LLVM_DYLIB TRUE)
+ if (DEFINED LLVM_DYLIB_COMPONENTS)
+ foreach(c in ${LLVM_LINK_COMPONENTS})
+ list(FIND LLVM_DYLIB_COMPONENTS ${c} C_IDX)
+ if (C_IDX EQUAL -1)
+ set(USE_LLVM_DYLIB FALSE)
+ break()
+ endif()
+ endforeach()
+ endif()
+endif()
+
+if(USE_LLVM_DYLIB)
set(LLVM_LINK_COMPONENTS)
endif()
@@ -22,11 +41,11 @@ add_llvm_tool(llvm-c-test
include-all.c
main.c
module.c
+ metadata.c
object.c
targets.c
)
-# Use libLLVM.so if it is available.
-if(TARGET LLVM)
+if(USE_LLVM_DYLIB)
target_link_libraries(llvm-c-test LLVM)
endif()
diff --git a/tools/llvm-c-test/llvm-c-test.h b/tools/llvm-c-test/llvm-c-test.h
index 0a25aa6..1b4976a 100644
--- a/tools/llvm-c-test/llvm-c-test.h
+++ b/tools/llvm-c-test/llvm-c-test.h
@@ -27,6 +27,10 @@ int calc(void);
// disassemble.c
int disassemble(void);
+// metadata.c
+int add_named_metadata_operand(void);
+int set_metadata(void);
+
// object.c
int object_list_sections(void);
int object_list_symbols(void);
diff --git a/tools/llvm-c-test/main.c b/tools/llvm-c-test/main.c
index 72f8b04..59cc749 100644
--- a/tools/llvm-c-test/main.c
+++ b/tools/llvm-c-test/main.c
@@ -65,6 +65,10 @@ int main(int argc, char **argv) {
return disassemble();
} else if (argc == 2 && !strcmp(argv[1], "--calc")) {
return calc();
+ } else if (argc == 2 && !strcmp(argv[1], "--add-named-metadata-operand")) {
+ return add_named_metadata_operand();
+ } else if (argc == 2 && !strcmp(argv[1], "--set-metadata")) {
+ return set_metadata();
} else {
print_usage();
}
diff --git a/tools/llvm-c-test/metadata.c b/tools/llvm-c-test/metadata.c
new file mode 100644
index 0000000..b64a696
--- /dev/null
+++ b/tools/llvm-c-test/metadata.c
@@ -0,0 +1,43 @@
+/*===-- object.c - tool for testing libLLVM and llvm-c API ----------------===*\
+|* *|
+|* The LLVM Compiler Infrastructure *|
+|* *|
+|* This file is distributed under the University of Illinois Open Source *|
+|* License. See LICENSE.TXT for details. *|
+|* *|
+|*===----------------------------------------------------------------------===*|
+|* *|
+|* This file implements the --add-named-metadata-operand and --set-metadata *|
+|* commands in llvm-c-test. *|
+|* *|
+\*===----------------------------------------------------------------------===*/
+
+#include "llvm-c-test.h"
+#include "llvm-c/Core.h"
+
+int add_named_metadata_operand(void) {
+ LLVMModuleRef m = LLVMModuleCreateWithName("Mod");
+ LLVMValueRef values[] = { LLVMConstInt(LLVMInt32Type(), 0, 0) };
+
+ // This used to trigger an assertion
+ LLVMAddNamedMetadataOperand(m, "name", LLVMMDNode(values, 1));
+
+ LLVMDisposeModule(m);
+
+ return 0;
+}
+
+int set_metadata(void) {
+ LLVMBuilderRef b = LLVMCreateBuilder();
+ LLVMValueRef values[] = { LLVMConstInt(LLVMInt32Type(), 0, 0) };
+
+ // This used to trigger an assertion
+ LLVMSetMetadata(
+ LLVMBuildRetVoid(b),
+ LLVMGetMDKindID("kind", 4),
+ LLVMMDNode(values, 1));
+
+ LLVMDisposeBuilder(b);
+
+ return 0;
+}