Commit 31be9f3f authored by aqjune's avatar aqjune
Browse files

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
parent 0aba69eb
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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
@nullptr = global i32* null

@aliased1 = alias i32, i32* @var
@aliased2 = internal alias i32, i32* @var
+7 −0
Original line number Diff line number Diff line
@@ -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);