From 6b16c2372cd66646852173e67268b661efebd4e3 Mon Sep 17 00:00:00 2001 From: Amaury Sechet Date: Tue, 16 Feb 2016 07:33:23 +0000 Subject: [PATCH] Do some refactoring in constant generation in the C API echo test. NFC llvm-svn: 260941 --- llvm/tools/llvm-c-test/echo.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/llvm/tools/llvm-c-test/echo.cpp b/llvm/tools/llvm-c-test/echo.cpp index 9dd9b10..d13a514 100644 --- a/llvm/tools/llvm-c-test/echo.cpp +++ b/llvm/tools/llvm-c-test/echo.cpp @@ -221,14 +221,12 @@ LLVMValueRef clone_constant(LLVMValueRef Cst, LLVMModuleRef M) { const char *Name = LLVMGetValueName(Cst); // Try function - LLVMValueRef Dst = LLVMGetNamedFunction(M, Name); - if (Dst != nullptr) - return Dst; + if (LLVMIsAFunction(Cst)) + return LLVMGetNamedFunction(M, Name); // Try global variable - Dst = LLVMGetNamedGlobal(M, Name); - if (Dst != nullptr) - return Dst; + if (LLVMIsAGlobalVariable(Cst)) + return LLVMGetNamedGlobal(M, Name); fprintf(stderr, "Could not find @%s\n", Name); exit(-1); @@ -243,8 +241,12 @@ LLVMValueRef clone_constant(LLVMValueRef Cst, LLVMModuleRef M) { if (LLVMIsUndef(Cst)) return LLVMGetUndef(TypeCloner(M).Clone(Cst)); - // This kind of constant is not supported. - report_fatal_error("Unsupported contant type"); + // This kind of constant is not supported + if (!LLVMIsAConstantExpr(Cst)) + report_fatal_error("Expected a constant expression"); + + // At this point, it must be a constant expression + report_fatal_error("ConstantExpression are not supported"); } struct FunCloner { -- 2.7.4