[llvm] 31be9f3 - Fix clone_constant_impl to correctly deal with null pointers
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 4 20:53:59 PST 2019
Author: aqjune
Date: 2019-11-05T13:53:52+09:00
New Revision: 31be9f3f7dee80c586d3beac9a65663d5628cf96
URL: https://github.com/llvm/llvm-project/commit/31be9f3f7dee80c586d3beac9a65663d5628cf96
DIFF: https://github.com/llvm/llvm-project/commit/31be9f3f7dee80c586d3beac9a65663d5628cf96.diff
LOG: Fix clone_constant_impl to correctly deal with null pointers
Summary:
This patch resolves llvm-c-test's following error
```
LLVM ERROR: LLVMGetValueKind returned incorrect type
```
which arises when the input bitcode contains a null pointer.
Reviewers: jdoerfert, CodaFi, deadalnix
Reviewed By: jdoerfert
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D68928
Added:
Modified:
llvm/test/Bindings/llvm-c/echo.ll
llvm/tools/llvm-c-test/echo.cpp
Removed:
################################################################################
diff --git a/llvm/test/Bindings/llvm-c/echo.ll b/llvm/test/Bindings/llvm-c/echo.ll
index c29991a12213..a244a65d91f9 100644
--- a/llvm/test/Bindings/llvm-c/echo.ll
+++ b/llvm/test/Bindings/llvm-c/echo.ll
@@ -21,6 +21,7 @@ module asm "classical GAS"
@protected = protected global i32 23
@section = global i32 27, section ".custom"
@align = global i32 31, align 4
+ at nullptr = global i32* null
@aliased1 = alias i32, i32* @var
@aliased2 = internal alias i32, i32* @var
diff --git a/llvm/tools/llvm-c-test/echo.cpp b/llvm/tools/llvm-c-test/echo.cpp
index 4d10a4bbfc05..8abbfb3fb0c0 100644
--- a/llvm/tools/llvm-c-test/echo.cpp
+++ b/llvm/tools/llvm-c-test/echo.cpp
@@ -326,6 +326,13 @@ static LLVMValueRef clone_constant_impl(LLVMValueRef Cst, LLVMModuleRef M) {
EltCount, LLVMIsPackedStruct(Ty));
}
+ // Try ConstantPointerNull
+ if (LLVMIsAConstantPointerNull(Cst)) {
+ check_value_kind(Cst, LLVMConstantPointerNullValueKind);
+ LLVMTypeRef Ty = TypeCloner(M).Clone(Cst);
+ return LLVMConstNull(Ty);
+ }
+
// Try undef
if (LLVMIsUndef(Cst)) {
check_value_kind(Cst, LLVMUndefValueValueKind);
More information about the llvm-commits
mailing list