aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenTypes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CodeGen/CodeGenTypes.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenTypes.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp b/clang/lib/CodeGen/CodeGenTypes.cpp
index fcce424747f1..abbf71daf1d5 100644
--- a/clang/lib/CodeGen/CodeGenTypes.cpp
+++ b/clang/lib/CodeGen/CodeGenTypes.cpp
@@ -67,7 +67,7 @@ void CodeGenTypes::addRecordTypeName(const RecordDecl *RD,
if (RD->getDeclContext())
RD->printQualifiedName(OS, Policy);
else
- RD->printName(OS);
+ RD->printName(OS, Policy);
} else if (const TypedefNameDecl *TDD = RD->getTypedefNameForAnonDecl()) {
// FIXME: We should not have to check for a null decl context here.
// Right now we do it because the implicit Obj-C decls don't have one.
@@ -655,7 +655,7 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
const ReferenceType *RTy = cast<ReferenceType>(Ty);
QualType ETy = RTy->getPointeeType();
llvm::Type *PointeeType = ConvertTypeForMem(ETy);
- unsigned AS = Context.getTargetAddressSpace(ETy);
+ unsigned AS = getTargetAddressSpace(ETy);
ResultType = llvm::PointerType::get(PointeeType, AS);
break;
}
@@ -665,7 +665,7 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
llvm::Type *PointeeType = ConvertTypeForMem(ETy);
if (PointeeType->isVoidTy())
PointeeType = llvm::Type::getInt8Ty(getLLVMContext());
- unsigned AS = Context.getTargetAddressSpace(ETy);
+ unsigned AS = getTargetAddressSpace(ETy);
ResultType = llvm::PointerType::get(PointeeType, AS);
break;
}
@@ -772,10 +772,10 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
// Block pointers lower to function type. For function type,
// getTargetAddressSpace() returns default address space for
// function pointer i.e. program address space. Therefore, for block
- // pointers, it is important to pass qualifiers when calling
- // getTargetAddressSpace(), to ensure that we get the address space
- // for data pointers and not function pointers.
- unsigned AS = Context.getTargetAddressSpace(FTy.getQualifiers());
+ // pointers, it is important to pass the pointee AST address space when
+ // calling getTargetAddressSpace(), to ensure that we get the LLVM IR
+ // address space for data pointers and not function pointers.
+ unsigned AS = Context.getTargetAddressSpace(FTy.getAddressSpace());
ResultType = llvm::PointerType::get(PointeeType, AS);
break;
}
@@ -807,8 +807,8 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
ResultType,
llvm::ArrayType::get(CGM.Int8Ty, (atomicSize - valueSize) / 8)
};
- ResultType = llvm::StructType::get(getLLVMContext(),
- llvm::makeArrayRef(elts));
+ ResultType =
+ llvm::StructType::get(getLLVMContext(), llvm::ArrayRef(elts));
}
break;
}
@@ -958,3 +958,13 @@ bool CodeGenTypes::isZeroInitializable(QualType T) {
bool CodeGenTypes::isZeroInitializable(const RecordDecl *RD) {
return getCGRecordLayout(RD).isZeroInitializable();
}
+
+unsigned CodeGenTypes::getTargetAddressSpace(QualType T) const {
+ // Return the address space for the type. If the type is a
+ // function type without an address space qualifier, the
+ // program address space is used. Otherwise, the target picks
+ // the best address space based on the type information
+ return T->isFunctionType() && !T.hasAddressSpace()
+ ? getDataLayout().getProgramAddressSpace()
+ : getContext().getTargetAddressSpace(T.getAddressSpace());
+}