aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp12
-rw-r--r--lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp2
-rw-r--r--lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp6
-rw-r--r--lib/Bitcode/NaCl/Writer/NaClValueEnumerator.h3
-rw-r--r--test/NaCl/Bitcode/forward-ref-pointer-intrinsic.ll46
-rw-r--r--test/NaCl/Bitcode/ptrtoint-elide.ll20
6 files changed, 72 insertions, 17 deletions
diff --git a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp
index 276d1d59b3..f5fd1ba0e7 100644
--- a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp
+++ b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp
@@ -1579,8 +1579,16 @@ bool NaClBitcodeReader::ParseFunctionBody(Function *F) {
}
// Non-void values get registered in the value table for future use.
- if (I && !I->getType()->isVoidTy())
- ValueList.AssignValue(I, NextValueNo++);
+ if (I && !I->getType()->isVoidTy()) {
+ Value *NewVal = I;
+ if (GetPNaClVersion() >= 2 &&
+ NewVal->getType()->isPointerTy() &&
+ ValueList.getValueFwdRef(NextValueNo)) {
+ // Forward-referenced values cannot have pointer type.
+ NewVal = ConvertOpToScalar(NewVal, CurBBNo);
+ }
+ ValueList.AssignValue(NewVal, NextValueNo++);
+ }
}
OutOfRecordLoop:
diff --git a/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp
index 6432740ba2..923d0b2c1e 100644
--- a/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp
+++ b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp
@@ -550,7 +550,7 @@ static void EmitFnForwardTypeRef(const Value *V,
VE.InsertFnForwardTypeRef(ValID)) {
SmallVector<unsigned, 2> Vals;
Vals.push_back(ValID);
- Vals.push_back(VE.getTypeID(V->getType()));
+ Vals.push_back(VE.getTypeID(VE.NormalizeScalarType(V->getType())));
Stream.EmitRecord(naclbitc::FUNC_CODE_INST_FORWARDTYPEREF, Vals,
FUNCTION_INST_FORWARDTYPEREF_ABBREV);
}
diff --git a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp
index ca34ac9c77..cabdc420c6 100644
--- a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp
+++ b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp
@@ -298,7 +298,7 @@ void NaClValueEnumerator::EnumerateValue(const Value *VIn) {
}
-Type *NaClValueEnumerator::NormalizeParamType(Type *Ty) const {
+Type *NaClValueEnumerator::NormalizeScalarType(Type *Ty) const {
// Strip pointer types.
if (Ty->isPointerTy() && PNaClVersion >= 2)
Ty = IntPtrType;
@@ -309,8 +309,8 @@ Type *NaClValueEnumerator::NormalizeType(Type *Ty) const {
if (FunctionType *FTy = dyn_cast<FunctionType>(Ty)) {
SmallVector<Type *, 8> ArgTypes;
for (unsigned I = 0, E = FTy->getNumParams(); I < E; ++I)
- ArgTypes.push_back(NormalizeParamType(FTy->getParamType(I)));
- Ty = FunctionType::get(NormalizeParamType(FTy->getReturnType()),
+ ArgTypes.push_back(NormalizeScalarType(FTy->getParamType(I)));
+ Ty = FunctionType::get(NormalizeScalarType(FTy->getReturnType()),
ArgTypes, false);
}
return Ty;
diff --git a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.h b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.h
index 5f25039e30..e756beb2f2 100644
--- a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.h
+++ b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.h
@@ -154,11 +154,12 @@ public:
return T == IntPtrType;
}
+ Type *NormalizeScalarType(Type *Ty) const;
+
private:
void OptimizeTypes(const Module *M);
void OptimizeConstants(unsigned CstStart, unsigned CstEnd);
- Type *NormalizeParamType(Type *Ty) const;
Type *NormalizeType(Type *Ty) const;
void EnumerateValue(const Value *V);
diff --git a/test/NaCl/Bitcode/forward-ref-pointer-intrinsic.ll b/test/NaCl/Bitcode/forward-ref-pointer-intrinsic.ll
new file mode 100644
index 0000000000..b6f8124a6f
--- /dev/null
+++ b/test/NaCl/Bitcode/forward-ref-pointer-intrinsic.ll
@@ -0,0 +1,46 @@
+; Test forward reference of a pointer-typed intrinsic result.
+
+; RUN: llvm-as < %s | pnacl-freeze --pnacl-version=1 | pnacl-thaw \
+; RUN: | llvm-dis - | FileCheck %s -check-prefix=TD1
+
+; RUN: llvm-as < %s | pnacl-freeze --pnacl-version=2 | pnacl-thaw \
+; RUN: | llvm-dis - | FileCheck %s -check-prefix=TD2
+
+
+declare i8* @llvm.nacl.read.tp()
+
+define i32 @forward_ref() {
+ br label %block1
+
+block2:
+ %1 = load i8* %3
+ %2 = ptrtoint i8* %3 to i32
+ ret i32 %2
+
+block1:
+ %3 = call i8* @llvm.nacl.read.tp()
+ br label %block2
+}
+
+; TD1: define i32 @forward_ref() {
+; TD1-NEXT: br label %block1
+; TD1: block2:
+; TD1-NEXT: %1 = load i8* %3
+; TD1-NEXT: %2 = ptrtoint i8* %3 to i32
+; TD1-NEXT: ret i32 %2
+; TD1: block1:
+; TD1-NEXT: %3 = call i8* @llvm.nacl.read.tp()
+; TD1-NEXT: br label %block2
+; TD1-NEXT: }
+
+; TD2: define i32 @forward_ref() {
+; TD2-NEXT: br label %block1
+; TD2: block2:
+; TD2-NEXT: %1 = inttoptr i32 %4 to i8*
+; TD2-NEXT: %2 = load i8* %1
+; TD2-NEXT: ret i32 %4
+; TD2: block1:
+; TD2-NEXT: %3 = call i8* @llvm.nacl.read.tp()
+; TD2-NEXT: %4 = ptrtoint i8* %3 to i32
+; TD2-NEXT: br label %block2
+; TD2-NEXT: }
diff --git a/test/NaCl/Bitcode/ptrtoint-elide.ll b/test/NaCl/Bitcode/ptrtoint-elide.ll
index bfca601d3f..5c95a79789 100644
--- a/test/NaCl/Bitcode/ptrtoint-elide.ll
+++ b/test/NaCl/Bitcode/ptrtoint-elide.ll
@@ -1016,35 +1016,35 @@ start:
; TD2: define void @PhiForwardRefs(i1) {
; TD2-NEXT: br label %start
; TD2: merge
-; TD2-NEXT: %2 = phi i32 [ %6, %true ], [ %9, %false ]
-; TD2-NEXT: %3 = phi i32 [ %5, %true ], [ %8, %false ]
+; TD2-NEXT: %2 = phi i32 [ %11, %true ], [ %11, %false ]
+; TD2-NEXT: %3 = phi i32 [ %5, %true ], [ %7, %false ]
; TD2-NEXT: ret void
; TD2: true:
-; TD2-NEXT: %4 = bitcast i8* %10 to i32*
+; TD2-NEXT: %4 = inttoptr i32 %9 to i32*
; TD2-NEXT: %5 = load i32* %4
-; TD2-NEXT: %6 = ptrtoint i8* %11 to i32
; TD2-NEXT: br label %merge
; TD2: false:
-; TD2-NEXT: %7 = bitcast i8* %10 to i32*
-; TD2-NEXT: %8 = load i32* %7
-; TD2-NEXT: %9 = ptrtoint i8* %11 to i32
+; TD2-NEXT: %6 = inttoptr i32 %9 to i32*
+; TD2-NEXT: %7 = load i32* %6
; TD2-NEXT: br label %merge
; TD2: start:
+; TD2-NEXT: %8 = alloca i8, i32 4, align 8
+; TD2-NEXT: %9 = ptrtoint i8* %8 to i32
; TD2-NEXT: %10 = alloca i8, i32 4, align 8
-; TD2-NEXT: %11 = alloca i8, i32 4, align 8
+; TD2-NEXT: %11 = ptrtoint i8* %10 to i32
; TD2-NEXT: br i1 %0, label %true, label %false
; TD2-NEXT: }
; PF2: <FUNCTION_BLOCK>
; PF2: </CONSTANTS_BLOCK>
; PF2-NEXT: <INST_BR op0=4/>
-; PF2-NEXT: <FORWARDTYPEREF op0=28 op1=3/>
+; PF2-NEXT: <FORWARDTYPEREF op0=28 op1=0/>
; PF2-NEXT: <INST_PHI op0=0 op1=11 op2=2 op3=11 op4=3/>
; PF2-NEXT: <FORWARDTYPEREF op0=25 op1=0/>
; PF2-NEXT: <FORWARDTYPEREF op0=26 op1=0/>
; PF2-NEXT: <INST_PHI op0=0 op1=3 op2=2 op3=5 op4=3/>
; PF2-NEXT: <INST_RET/>
-; PF2-NEXT: <FORWARDTYPEREF op0=27 op1=3/>
+; PF2-NEXT: <FORWARDTYPEREF op0=27 op1=0/>
; PF2-NEXT: <INST_LOAD op0=4294967294 op1=0 op2=0/>
; PF2-NEXT: <INST_BR op0=1/>
; PF2-NEXT: <INST_LOAD op0=4294967295 op1=0 op2=0/>