[analyzer] Use the new registration mechanism on the non-path-sensitive-checkers:
[clang.git] / lib / CodeGen / CGCXXABI.cpp
blob8373b660b2f4573ea65e039b0b28e6f62976bd9d
1 //===----- CGCXXABI.cpp - Interface to C++ ABIs -----------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This provides an abstract class for C++ code generation. Concrete subclasses
11 // of this implement code generation for specific C++ ABIs.
13 //===----------------------------------------------------------------------===//
15 #include "CGCXXABI.h"
17 using namespace clang;
18 using namespace CodeGen;
20 CGCXXABI::~CGCXXABI() { }
22 static void ErrorUnsupportedABI(CodeGenFunction &CGF,
23 llvm::StringRef S) {
24 Diagnostic &Diags = CGF.CGM.getDiags();
25 unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Error,
26 "cannot yet compile %1 in this ABI");
27 Diags.Report(CGF.getContext().getFullLoc(CGF.CurCodeDecl->getLocation()),
28 DiagID)
29 << S;
32 static llvm::Constant *GetBogusMemberPointer(CodeGenModule &CGM,
33 QualType T) {
34 return llvm::Constant::getNullValue(CGM.getTypes().ConvertType(T));
37 const llvm::Type *
38 CGCXXABI::ConvertMemberPointerType(const MemberPointerType *MPT) {
39 return CGM.getTypes().ConvertType(CGM.getContext().getPointerDiffType());
42 llvm::Value *CGCXXABI::EmitLoadOfMemberFunctionPointer(CodeGenFunction &CGF,
43 llvm::Value *&This,
44 llvm::Value *MemPtr,
45 const MemberPointerType *MPT) {
46 ErrorUnsupportedABI(CGF, "calls through member pointers");
48 const FunctionProtoType *FPT =
49 MPT->getPointeeType()->getAs<FunctionProtoType>();
50 const CXXRecordDecl *RD =
51 cast<CXXRecordDecl>(MPT->getClass()->getAs<RecordType>()->getDecl());
52 const llvm::FunctionType *FTy =
53 CGM.getTypes().GetFunctionType(CGM.getTypes().getFunctionInfo(RD, FPT),
54 FPT->isVariadic());
55 return llvm::Constant::getNullValue(FTy->getPointerTo());
58 llvm::Value *CGCXXABI::EmitMemberDataPointerAddress(CodeGenFunction &CGF,
59 llvm::Value *Base,
60 llvm::Value *MemPtr,
61 const MemberPointerType *MPT) {
62 ErrorUnsupportedABI(CGF, "loads of member pointers");
63 const llvm::Type *Ty = CGF.ConvertType(MPT->getPointeeType())->getPointerTo();
64 return llvm::Constant::getNullValue(Ty);
67 llvm::Value *CGCXXABI::EmitMemberPointerConversion(CodeGenFunction &CGF,
68 const CastExpr *E,
69 llvm::Value *Src) {
70 ErrorUnsupportedABI(CGF, "member function pointer conversions");
71 return GetBogusMemberPointer(CGM, E->getType());
74 llvm::Value *
75 CGCXXABI::EmitMemberPointerComparison(CodeGenFunction &CGF,
76 llvm::Value *L,
77 llvm::Value *R,
78 const MemberPointerType *MPT,
79 bool Inequality) {
80 ErrorUnsupportedABI(CGF, "member function pointer comparison");
81 return CGF.Builder.getFalse();
84 llvm::Value *
85 CGCXXABI::EmitMemberPointerIsNotNull(CodeGenFunction &CGF,
86 llvm::Value *MemPtr,
87 const MemberPointerType *MPT) {
88 ErrorUnsupportedABI(CGF, "member function pointer null testing");
89 return CGF.Builder.getFalse();
92 llvm::Constant *
93 CGCXXABI::EmitMemberPointerConversion(llvm::Constant *C, const CastExpr *E) {
94 return GetBogusMemberPointer(CGM, E->getType());
97 llvm::Constant *
98 CGCXXABI::EmitNullMemberPointer(const MemberPointerType *MPT) {
99 return GetBogusMemberPointer(CGM, QualType(MPT, 0));
102 llvm::Constant *CGCXXABI::EmitMemberPointer(const CXXMethodDecl *MD) {
103 return GetBogusMemberPointer(CGM,
104 CGM.getContext().getMemberPointerType(MD->getType(),
105 MD->getParent()->getTypeForDecl()));
108 llvm::Constant *CGCXXABI::EmitMemberDataPointer(const MemberPointerType *MPT,
109 CharUnits offset) {
110 return GetBogusMemberPointer(CGM, QualType(MPT, 0));
113 bool CGCXXABI::isZeroInitializable(const MemberPointerType *MPT) {
114 // Fake answer.
115 return true;
118 void CGCXXABI::BuildThisParam(CodeGenFunction &CGF, FunctionArgList &Params) {
119 const CXXMethodDecl *MD = cast<CXXMethodDecl>(CGF.CurGD.getDecl());
121 // FIXME: I'm not entirely sure I like using a fake decl just for code
122 // generation. Maybe we can come up with a better way?
123 ImplicitParamDecl *ThisDecl
124 = ImplicitParamDecl::Create(CGM.getContext(), 0, MD->getLocation(),
125 &CGM.getContext().Idents.get("this"),
126 MD->getThisType(CGM.getContext()));
127 Params.push_back(std::make_pair(ThisDecl, ThisDecl->getType()));
128 getThisDecl(CGF) = ThisDecl;
131 void CGCXXABI::EmitThisParam(CodeGenFunction &CGF) {
132 /// Initialize the 'this' slot.
133 assert(getThisDecl(CGF) && "no 'this' variable for function");
134 getThisValue(CGF)
135 = CGF.Builder.CreateLoad(CGF.GetAddrOfLocalVar(getThisDecl(CGF)),
136 "this");
139 void CGCXXABI::EmitReturnFromThunk(CodeGenFunction &CGF,
140 RValue RV, QualType ResultType) {
141 CGF.EmitReturnOfRValue(RV, ResultType);
144 CharUnits CGCXXABI::GetArrayCookieSize(const CXXNewExpr *expr) {
145 return CharUnits::Zero();
148 llvm::Value *CGCXXABI::InitializeArrayCookie(CodeGenFunction &CGF,
149 llvm::Value *NewPtr,
150 llvm::Value *NumElements,
151 const CXXNewExpr *expr,
152 QualType ElementType) {
153 // Should never be called.
154 ErrorUnsupportedABI(CGF, "array cookie initialization");
155 return 0;
158 void CGCXXABI::ReadArrayCookie(CodeGenFunction &CGF, llvm::Value *Ptr,
159 const CXXDeleteExpr *expr, QualType ElementType,
160 llvm::Value *&NumElements,
161 llvm::Value *&AllocPtr, CharUnits &CookieSize) {
162 ErrorUnsupportedABI(CGF, "array cookie reading");
164 // This should be enough to avoid assertions.
165 NumElements = 0;
166 AllocPtr = llvm::Constant::getNullValue(CGF.Builder.getInt8PtrTy());
167 CookieSize = CharUnits::Zero();
170 void CGCXXABI::EmitGuardedInit(CodeGenFunction &CGF,
171 const VarDecl &D,
172 llvm::GlobalVariable *GV) {
173 ErrorUnsupportedABI(CGF, "static local variable initialization");