245 changes: 170 additions & 75 deletions clang/lib/CodeGen/CGObjCGNU.cpp

Large diffs are not rendered by default.

58 changes: 50 additions & 8 deletions clang/lib/CodeGen/CGObjCRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@

#include "CGObjCRuntime.h"
#include "CGCleanup.h"
#include "CGCXXABI.h"
#include "CGRecordLayout.h"
#include "CodeGenFunction.h"
#include "CodeGenModule.h"
#include "clang/AST/RecordLayout.h"
#include "clang/AST/StmtObjC.h"
#include "clang/CodeGen/CGFunctionInfo.h"
#include "llvm/IR/CallSite.h"
#include "llvm/Support/SaveAndRestore.h"

using namespace clang;
using namespace CodeGen;
Expand Down Expand Up @@ -120,6 +122,8 @@ namespace {
const Stmt *Body;
llvm::BasicBlock *Block;
llvm::Constant *TypeInfo;
/// Flags used to differentiate cleanups and catchalls in Windows SEH
unsigned Flags;
};

struct CallObjCEndCatch final : EHScopeStack::Cleanup {
Expand Down Expand Up @@ -148,13 +152,17 @@ void CGObjCRuntime::EmitTryCatchStmt(CodeGenFunction &CGF,
if (S.getNumCatchStmts())
Cont = CGF.getJumpDestInCurrentScope("eh.cont");

bool useFunclets = EHPersonality::get(CGF).usesFuncletPads();

CodeGenFunction::FinallyInfo FinallyInfo;
if (const ObjCAtFinallyStmt *Finally = S.getFinallyStmt())
FinallyInfo.enter(CGF, Finally->getFinallyBody(),
beginCatchFn, endCatchFn, exceptionRethrowFn);
if (!useFunclets)
if (const ObjCAtFinallyStmt *Finally = S.getFinallyStmt())
FinallyInfo.enter(CGF, Finally->getFinallyBody(),
beginCatchFn, endCatchFn, exceptionRethrowFn);

SmallVector<CatchHandler, 8> Handlers;


// Enter the catch, if there is one.
if (S.getNumCatchStmts()) {
for (unsigned I = 0, N = S.getNumCatchStmts(); I != N; ++I) {
Expand All @@ -166,10 +174,13 @@ void CGObjCRuntime::EmitTryCatchStmt(CodeGenFunction &CGF,
Handler.Variable = CatchDecl;
Handler.Body = CatchStmt->getCatchBody();
Handler.Block = CGF.createBasicBlock("catch");
Handler.Flags = 0;

// @catch(...) always matches.
if (!CatchDecl) {
Handler.TypeInfo = nullptr; // catch-all
auto catchAll = getCatchAllTypeInfo();
Handler.TypeInfo = catchAll.RTTI;
Handler.Flags = catchAll.Flags;
// Don't consider any other catches.
break;
}
Expand All @@ -179,9 +190,31 @@ void CGObjCRuntime::EmitTryCatchStmt(CodeGenFunction &CGF,

EHCatchScope *Catch = CGF.EHStack.pushCatch(Handlers.size());
for (unsigned I = 0, E = Handlers.size(); I != E; ++I)
Catch->setHandler(I, Handlers[I].TypeInfo, Handlers[I].Block);
Catch->setHandler(I, { Handlers[I].TypeInfo, Handlers[I].Flags }, Handlers[I].Block);
}

if (useFunclets)
if (const ObjCAtFinallyStmt *Finally = S.getFinallyStmt()) {
CodeGenFunction HelperCGF(CGM, /*suppressNewContext=*/true);
if (!CGF.CurSEHParent)
CGF.CurSEHParent = cast<NamedDecl>(CGF.CurFuncDecl);
// Outline the finally block.
const Stmt *FinallyBlock = Finally->getFinallyBody();
HelperCGF.startOutlinedSEHHelper(CGF, /*isFilter*/false, FinallyBlock);

// Emit the original filter expression, convert to i32, and return.
HelperCGF.EmitStmt(FinallyBlock);

HelperCGF.FinishFunction(FinallyBlock->getLocEnd());

llvm::Function *FinallyFunc = HelperCGF.CurFn;


// Push a cleanup for __finally blocks.
CGF.pushSEHCleanup(NormalAndEHCleanup, FinallyFunc);
}


// Emit the try body.
CGF.EmitStmt(S.getTryBody());

Expand All @@ -197,6 +230,13 @@ void CGObjCRuntime::EmitTryCatchStmt(CodeGenFunction &CGF,
CatchHandler &Handler = Handlers[I];

CGF.EmitBlock(Handler.Block);
llvm::CatchPadInst *CPI = nullptr;
SaveAndRestore<llvm::Instruction *> RestoreCurrentFuncletPad(CGF.CurrentFuncletPad);
if (useFunclets)
if ((CPI = dyn_cast_or_null<llvm::CatchPadInst>(Handler.Block->getFirstNonPHI()))) {
CGF.CurrentFuncletPad = CPI;
CPI->setOperand(2, CGF.getExceptionSlot().getPointer());
}
llvm::Value *RawExn = CGF.getExceptionFromSlot();

// Enter the catch.
Expand All @@ -223,6 +263,8 @@ void CGObjCRuntime::EmitTryCatchStmt(CodeGenFunction &CGF,
CGF.EmitAutoVarDecl(*CatchParam);
EmitInitOfCatchParam(CGF, CastExn, CatchParam);
}
if (CPI)
CGF.EHStack.pushCleanup<CatchRetScope>(NormalCleanup, CPI);

CGF.ObjCEHValueStack.push_back(Exn);
CGF.EmitStmt(Handler.Body);
Expand All @@ -232,13 +274,13 @@ void CGObjCRuntime::EmitTryCatchStmt(CodeGenFunction &CGF,
cleanups.ForceCleanup();

CGF.EmitBranchThroughCleanup(Cont);
}
}

// Go back to the try-statement fallthrough.
CGF.Builder.restoreIP(SavedIP);

// Pop out of the finally.
if (S.getFinallyStmt())
if (!useFunclets && S.getFinallyStmt())
FinallyInfo.exit(CGF);

if (Cont.isValid())
Expand Down Expand Up @@ -277,7 +319,7 @@ namespace {
: SyncExitFn(SyncExitFn), SyncArg(SyncArg) {}

void Emit(CodeGenFunction &CGF, Flags flags) override {
CGF.Builder.CreateCall(SyncExitFn, SyncArg)->setDoesNotThrow();
CGF.EmitNounwindRuntimeCall(SyncExitFn, SyncArg);
}
};
}
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/CodeGen/CGObjCRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define LLVM_CLANG_LIB_CODEGEN_CGOBJCRUNTIME_H
#include "CGBuilder.h"
#include "CGCall.h"
#include "CGCleanup.h"
#include "CGValue.h"
#include "clang/AST/DeclObjC.h"
#include "clang/Basic/IdentifierTable.h" // Selector
Expand Down Expand Up @@ -141,6 +142,8 @@ class CGObjCRuntime {
/// error to Sema.
virtual llvm::Constant *GetEHType(QualType T) = 0;

virtual CatchTypeInfo getCatchAllTypeInfo() { return { nullptr, 0 }; }

/// Generate a constant string object.
virtual ConstantAddress GenerateConstantString(const StringLiteral *) = 0;

Expand Down
4 changes: 3 additions & 1 deletion clang/lib/CodeGen/CodeGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ class CodeGenFunction : public CodeGenTypeCache {
/// potentially set the return value.
bool SawAsmBlock = false;

const FunctionDecl *CurSEHParent = nullptr;
const NamedDecl *CurSEHParent = nullptr;

/// True if the current function is an outlined SEH helper. This can be a
/// finally block or filter expression.
Expand Down Expand Up @@ -2878,6 +2878,8 @@ class CodeGenFunction : public CodeGenTypeCache {
void EnterSEHTryStmt(const SEHTryStmt &S);
void ExitSEHTryStmt(const SEHTryStmt &S);

void pushSEHCleanup(CleanupKind kind,
llvm::Function *FinallyFunc);
void startOutlinedSEHHelper(CodeGenFunction &ParentCGF, bool IsFilter,
const Stmt *OutlinedStmt);

Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4915,7 +4915,8 @@ ObjCRuntime Clang::AddObjCRuntimeArgs(const ArgList &args,
}
if ((runtime.getKind() == ObjCRuntime::GNUstep) &&
(runtime.getVersion() >= VersionTuple(2, 0)))
if (!getToolChain().getTriple().isOSBinFormatELF()) {
if (!getToolChain().getTriple().isOSBinFormatELF() &&
!getToolChain().getTriple().isOSBinFormatCOFF()) {
getToolChain().getDriver().Diag(
diag::err_drv_gnustep_objc_runtime_incompatible_binary)
<< runtime.getVersion().getMajor();
Expand Down
39 changes: 37 additions & 2 deletions clang/test/CodeGenObjC/gnu-init.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -triple x86_64-unknown-freebsd -S -emit-llvm -fobjc-runtime=gnustep-2.0 -o - %s | FileCheck %s -check-prefix=CHECK-NEW
// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -S -emit-llvm -fobjc-runtime=gnustep-2.0 -o - %s | FileCheck %s -check-prefix=CHECK-WIN
// RUN: %clang_cc1 -triple x86_64-unknown-freebsd -S -emit-llvm -fobjc-runtime=gnustep-1.8 -o - %s | FileCheck %s -check-prefix=CHECK-OLD

// Almost minimal Objective-C file, check that it emits calls to the correct
Expand Down Expand Up @@ -49,9 +50,9 @@ @implementation X @end
// CHECK-NEW: @.objc_null_class_alias = linkonce_odr hidden global { i8*, i8* } zeroinitializer, section "__objc_class_aliases", comdat, align 8
// CHECK-NEW: @.objc_null_constant_string = linkonce_odr hidden global { i8*, i32, i32, i32, i32, i8* } zeroinitializer, section "__objc_constant_string", comdat, align 8
// Make sure that the null symbols are not going to be removed, even by linking.
// CHECK-NEW: @llvm.used = appending global [7 x i8*] [i8* bitcast ({ { i8*, i8*, i8*, i64, i64, i64, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i64, i8* }*, i8*, i8*, i64, i64, i64, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i64, i8* }** @._OBJC_INIT_CLASS_X to i8*), i8* bitcast ({ i8*, i8* }* @.objc_null_selector to i8*), i8* bitcast ({ i8*, i8*, i8*, i8*, i8*, i8*, i8* }* @.objc_null_category to i8*), i8* bitcast ({ i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8* }* @.objc_null_protocol to i8*), i8* bitcast ({ i8* }* @.objc_null_protocol_ref to i8*), i8* bitcast ({ i8*, i8* }* @.objc_null_class_alias to i8*), i8* bitcast ({ i8*, i32, i32, i32, i32, i8* }* @.objc_null_constant_string to i8*)], section "llvm.metadata"
// CHECK-NEW: @llvm.used = appending global [8 x i8*] [i8* bitcast ({ { i8*, i8*, i8*, i64, i64, i64, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i64, i8* }*, i8*, i8*, i64, i64, i64, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i64, i8* }** @._OBJC_INIT_CLASS_X to i8*), i8* bitcast (void ()** @.objc_ctor to i8*), i8* bitcast ({ i8*, i8* }* @.objc_null_selector to i8*), i8* bitcast ({ i8*, i8*, i8*, i8*, i8*, i8*, i8* }* @.objc_null_category to i8*), i8* bitcast ({ i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8* }* @.objc_null_protocol to i8*), i8* bitcast ({ i8* }* @.objc_null_protocol_ref to i8*), i8* bitcast ({ i8*, i8* }* @.objc_null_class_alias to i8*), i8* bitcast ({ i8*, i32, i32, i32, i32, i8* }* @.objc_null_constant_string to i8*)], section "llvm.metadata"
// Make sure that the load function and the reference to it are marked as used.
// CHECK-NEW: @llvm.compiler.used = appending global [2 x i8*] [i8* bitcast (void ()* @.objcv2_load_function to i8*), i8* bitcast (void ()** @.objc_ctor to i8*)], section "llvm.metadata"
// CHECK-NEW: @llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (void ()* @.objcv2_load_function to i8*)], section "llvm.metadata"

// Check that we emit the load function in a comdat and that it does the right thing.
// CHECK-NEW: define linkonce_odr hidden void @.objcv2_load_function() comdat {
Expand All @@ -67,3 +68,37 @@ @implementation X @end
// CHECK-OLD-NEXT: entry:
// CHECK-OLD-NEXT: call void ({ i64, i64, i8*, { i64, { i8*, i8* }*, i16, i16, [4 x i8*] }* }*, ...) @__objc_exec_class({ i64, i64, i8*, { i64, { i8*, i8* }*, i16, i16, [4 x i8*] }* }* @4)



// Make sure all of our section boundary variables are emitted correctly.
// CHECK-WIN: @__start___objc_selectors = linkonce_odr hidden global %.objc_section_sentinel zeroinitializer, section "__objc_selectors$a", comdat, align 1
// CHECK-WIN: @__stop__objc_selectors = linkonce_odr hidden global %.objc_section_sentinel zeroinitializer, section "__objc_selectors$z", comdat, align 1
// CHECK-WIN: @__start___objc_classes = linkonce_odr hidden global %.objc_section_sentinel zeroinitializer, section "__objc_classes$a", comdat, align 1
// CHECK-WIN: @__stop__objc_classes = linkonce_odr hidden global %.objc_section_sentinel zeroinitializer, section "__objc_classes$z", comdat, align 1
// CHECK-WIN: @__start___objc_class_refs = linkonce_odr hidden global %.objc_section_sentinel zeroinitializer, section "__objc_class_refs$a", comdat, align 1
// CHECK-WIN: @__stop__objc_class_refs = linkonce_odr hidden global %.objc_section_sentinel zeroinitializer, section "__objc_class_refs$z", comdat, align 1
// CHECK-WIN: @__start___objc_cats = linkonce_odr hidden global %.objc_section_sentinel zeroinitializer, section "__objc_cats$a", comdat, align 1
// CHECK-WIN: @__stop__objc_cats = linkonce_odr hidden global %.objc_section_sentinel zeroinitializer, section "__objc_cats$z", comdat, align 1
// CHECK-WIN: @__start___objc_protocols = linkonce_odr hidden global %.objc_section_sentinel zeroinitializer, section "__objc_protocols$a", comdat, align 1
// CHECK-WIN: @__stop__objc_protocols = linkonce_odr hidden global %.objc_section_sentinel zeroinitializer, section "__objc_protocols$z", comdat, align 1
// CHECK-WIN: @__start___objc_protocol_refs = linkonce_odr hidden global %.objc_section_sentinel zeroinitializer, section "__objc_protocol_refs$a", comdat, align 1
// CHECK-WIN: @__stop__objc_protocol_refs = linkonce_odr hidden global %.objc_section_sentinel zeroinitializer, section "__objc_protocol_refs$z", comdat, align 1
// CHECK-WIN: @__start___objc_class_aliases = linkonce_odr hidden global %.objc_section_sentinel zeroinitializer, section "__objc_class_aliases$a", comdat, align 1
// CHECK-WIN: @__stop__objc_class_aliases = linkonce_odr hidden global %.objc_section_sentinel zeroinitializer, section "__objc_class_aliases$z", comdat, align 1
// CHECK-WIN: @__start___objc_constant_string = linkonce_odr hidden global %.objc_section_sentinel zeroinitializer, section "__objc_constant_string$a", comdat, align 1
// CHECK-WIN: @__stop__objc_constant_string = linkonce_odr hidden global %.objc_section_sentinel zeroinitializer, section "__objc_constant_string$z", comdat, align 1
// CHECK-WIN: @.objc_init = linkonce_odr hidden global { i64, %.objc_section_sentinel*, %.objc_section_sentinel*, %.objc_section_sentinel*, %.objc_section_sentinel*, %.objc_section_sentinel*, %.objc_section_sentinel*, %.objc_section_sentinel*, %.objc_section_sentinel*, %.objc_section_sentinel*, %.objc_section_sentinel*, %.objc_section_sentinel*, %.objc_section_sentinel*, %.objc_section_sentinel*, %.objc_section_sentinel*, %.objc_section_sentinel*, %.objc_section_sentinel* } { i64 0, %.objc_section_sentinel* @__start___objc_selectors, %.objc_section_sentinel* @__stop__objc_selectors, %.objc_section_sentinel* @__start___objc_classes, %.objc_section_sentinel* @__stop__objc_classes, %.objc_section_sentinel* @__start___objc_class_refs, %.objc_section_sentinel* @__stop__objc_class_refs, %.objc_section_sentinel* @__start___objc_cats, %.objc_section_sentinel* @__stop__objc_cats, %.objc_section_sentinel* @__start___objc_protocols, %.objc_section_sentinel* @__stop__objc_protocols, %.objc_section_sentinel* @__start___objc_protocol_refs, %.objc_section_sentinel* @__stop__objc_protocol_refs, %.objc_section_sentinel* @__start___objc_class_aliases, %.objc_section_sentinel* @__stop__objc_class_aliases, %.objc_section_sentinel* @__start___objc_constant_string, %.objc_section_sentinel* @__stop__objc_constant_string }, comdat, align 8

// Make sure our init variable is in the correct section for late library init.
// CHECK-WIN: @.objc_ctor = linkonce hidden constant void ()* @.objcv2_load_function, section ".CRT$XCLz", comdat

// We shouldn't have emitted any null placeholders on Windows.
// CHECK-WIN: @llvm.used = appending global [2 x i8*] [i8* bitcast ({ { i8*, i8*, i8*, i32, i32, i32, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i32, i8* }*, i8*, i8*, i32, i32, i32, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i32, i8* }** @._OBJC_INIT_CLASS_X to i8*), i8* bitcast (void ()** @.objc_ctor to i8*)], section "llvm.metadata"
// CHECK-WIN: @llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (void ()* @.objcv2_load_function to i8*)], section "llvm.metadata"

// Check our load function is in a comdat.
// CHECK-WIN: define linkonce_odr hidden void @.objcv2_load_function() comdat {

// Make sure we have dllimport on the load function
// CHECK-WIN: declare dllimport void @__objc_load

6 changes: 3 additions & 3 deletions clang/test/CodeGenObjC/gnustep2-proto.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ + (void*)y;

// Check that we're emitting the protocol and a correctly initialised
// indirection variable.
// CHECK: @._OBJC_PROTOCOL_X = global
// CHECK: @._OBJC_PROTOCOL_X = global
// CHECK-SAME: , section "__objc_protocols", comdat, align 8
// CHECK: @._OBJC_REF_PROTOCOL_X = global
// CHECK: @._OBJC_REF_PROTOCOL_X = linkonce_odr global
// CHECK-SAME: @._OBJC_PROTOCOL_X
// CHECK-SAME: , section "__objc_protocol_refs", align 8
// CHECK-SAME: , section "__objc_protocol_refs", comdat, align 8


// Check that we load from the indirection variable on protocol references.
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGenObjCXX/arc-marker-funclet.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void g() {
}
}

// CHECK: call i8* @"?f@@YAPAUobjc_object@@XZ"() [ "funclet"(token %1) ]
// CHECK: call i8* @"?f@@YAPAU.objc_object@@XZ"() [ "funclet"(token %1) ]
// CHECK-NEXT: call void asm sideeffect "movl{{.*}}%ebp, %ebp{{.*}}", ""() [ "funclet"(token %1) ]

// The corresponding f() call was invoked from the entry basic block.
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGenObjCXX/microsoft-abi-arc-param-order.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

// Verify that we destruct things from left to right in the MS C++ ABI: a, b, c, d.
//
// CHECK-LABEL: define dso_local void @"?test_arc_order@@YAXUA@@PAUobjc_object@@01@Z"
// CHECK-LABEL: define dso_local void @"?test_arc_order@@YAXUA@@PAU.objc_object@@01@Z"
// CHECK: (<{ %struct.A, i8*, %struct.A, i8* }>* inalloca)
void test_arc_order(A a, id __attribute__((ns_consumed)) b , A c, id __attribute__((ns_consumed)) d) {
// CHECK: call x86_thiscallcc void @"??1A@@QAE@XZ"(%struct.A* %{{.*}})
Expand Down
38 changes: 19 additions & 19 deletions clang/test/CodeGenObjCXX/msabi-objc-extensions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,61 @@ @protocol Q;
@class I;

void f(id<P>, id, id<P>, id) {}
// CHECK-LABEL: "?f@@YAXPAU?$objc_object@U?$Protocol@UP@@@__ObjC@@@@PAUobjc_object@@01@Z"
// CHECK-LABEL: "?f@@YAXPAU?$.objc_object@U?$Protocol@UP@@@__ObjC@@@@PAU.objc_object@@01@Z"

void f(id, id<P>, id<P>, id) {}
// CHECK-LABEL: "?f@@YAXPAUobjc_object@@PAU?$objc_object@U?$Protocol@UP@@@__ObjC@@@@10@Z"
// CHECK-LABEL: "?f@@YAXPAU.objc_object@@PAU?$.objc_object@U?$Protocol@UP@@@__ObjC@@@@10@Z"

void f(id<P>, id<P>) {}
// CHECK-LABEL: "?f@@YAXPAU?$objc_object@U?$Protocol@UP@@@__ObjC@@@@0@Z"
// CHECK-LABEL: "?f@@YAXPAU?$.objc_object@U?$Protocol@UP@@@__ObjC@@@@0@Z"

void f(id<P>) {}
// CHECK-LABEL: "?f@@YAXPAU?$objc_object@U?$Protocol@UP@@@__ObjC@@@@@Z"
// CHECK-LABEL: "?f@@YAXPAU?$.objc_object@U?$Protocol@UP@@@__ObjC@@@@@Z"

void f(id<P, Q>) {}
// CHECK-LABEL: "?f@@YAXPAU?$objc_object@U?$Protocol@UP@@@__ObjC@@U?$Protocol@UQ@@@2@@@@Z"
// CHECK-LABEL: "?f@@YAXPAU?$.objc_object@U?$Protocol@UP@@@__ObjC@@U?$Protocol@UQ@@@2@@@@Z"

void f(Class<P>) {}
// CHECK-LABEL: "?f@@YAXPAU?$objc_class@U?$Protocol@UP@@@__ObjC@@@@@Z"
// CHECK-LABEL: "?f@@YAXPAU?$.objc_class@U?$Protocol@UP@@@__ObjC@@@@@Z"

void f(Class<P, Q>) {}
// CHECK-LABEL: "?f@@YAXPAU?$objc_class@U?$Protocol@UP@@@__ObjC@@U?$Protocol@UQ@@@2@@@@Z"
// CHECK-LABEL: "?f@@YAXPAU?$.objc_class@U?$Protocol@UP@@@__ObjC@@U?$Protocol@UQ@@@2@@@@Z"

void f(I<P> *) {}
// CHECK-LABEL: "?f@@YAXPAU?$I@U?$Protocol@UP@@@__ObjC@@@@@Z"
// CHECK-LABEL: "?f@@YAXPAU?$.objc_cls_I@U?$Protocol@UP@@@__ObjC@@@@@Z"

void f(I<P, Q> *) {}
// CHECK-LABEL: "?f@@YAXPAU?$I@U?$Protocol@UP@@@__ObjC@@U?$Protocol@UQ@@@2@@@@Z"
// CHECK-LABEL: "?f@@YAXPAU?$.objc_cls_I@U?$Protocol@UP@@@__ObjC@@U?$Protocol@UQ@@@2@@@@Z"

template <typename>
struct S {};

void f(S<__unsafe_unretained id>) {}
// CHECK-LABEL: "?f@@YAXU?$S@PAUobjc_object@@@@@Z"
// CHECK-LABEL: "?f@@YAXU?$S@PAU.objc_object@@@@@Z"

void f(S<__autoreleasing id>) {}
// CHECK-LABEL: "?f@@YAXU?$S@U?$Autoreleasing@PAUobjc_object@@@__ObjC@@@@@Z"
// CHECK-LABEL: "?f@@YAXU?$S@U?$Autoreleasing@PAU.objc_object@@@__ObjC@@@@@Z"

void f(S<__strong id>) {}
// CHECK-LABEL: "?f@@YAXU?$S@U?$Strong@PAUobjc_object@@@__ObjC@@@@@Z"
// CHECK-LABEL: "?f@@YAXU?$S@U?$Strong@PAU.objc_object@@@__ObjC@@@@@Z"

void f(S<__weak id>) {}
// CHECK-LABEL: "?f@@YAXU?$S@U?$Weak@PAUobjc_object@@@__ObjC@@@@@Z"
// CHECK-LABEL: "?f@@YAXU?$S@U?$Weak@PAU.objc_object@@@__ObjC@@@@@Z"

void w(__weak id) {}
// CHECK-LABEL: "?w@@YAXPAUobjc_object@@@Z"
// CHECK-LABEL: "?w@@YAXPAU.objc_object@@@Z"

void s(__strong id) {}
// CHECK-LABEL: "?s@@YAXPAUobjc_object@@@Z"
// CHECK-LABEL: "?s@@YAXPAU.objc_object@@@Z"

void a(__autoreleasing id) {}
// CHECK-LABEL: "?a@@YAXPAUobjc_object@@@Z"
// CHECK-LABEL: "?a@@YAXPAU.objc_object@@@Z"

void u(__unsafe_unretained id) {}
// CHECK-LABEL: "?u@@YAXPAUobjc_object@@@Z"
// CHECK-LABEL: "?u@@YAXPAU.objc_object@@@Z"

S<__autoreleasing id> g() { return S<__autoreleasing id>(); }
// CHECK-LABEL: "?g@@YA?AU?$S@U?$Autoreleasing@PAUobjc_object@@@__ObjC@@@@XZ"
// CHECK-LABEL: "?g@@YA?AU?$S@U?$Autoreleasing@PAU.objc_object@@@__ObjC@@@@XZ"

__autoreleasing id h() { return nullptr; }
// CHECK-LABEL: "?h@@YAPAUobjc_object@@XZ"
// CHECK-LABEL: "?h@@YAPAU.objc_object@@XZ"
114 changes: 57 additions & 57 deletions clang/test/CodeGenObjCXX/msabi-objc-types.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,166 +3,166 @@
@class I;

id kid;
// CHECK: @"?kid@@3PAUobjc_object@@A" = dso_local global
// CHECK: @"?kid@@3PAU.objc_object@@A" = dso_local global

Class klass;
// CHECK: @"?klass@@3PAUobjc_class@@A" = dso_local global
// CHECK: @"?klass@@3PAU.objc_class@@A" = dso_local global

I *kI;
// CHECK: @"?kI@@3PAUI@@A" = dso_local global
// CHECK: @"?kI@@3PAU.objc_cls_I@@A" = dso_local global

void f(I *) {}
// CHECK-LABEL: "?f@@YAXPAUI@@@Z"
// CHECK-LABEL: "?f@@YAXPAU.objc_cls_I@@@Z"

void f(const I *) {}
// CHECK-LABEL: "?f@@YAXPBUI@@@Z"
// CHECK-LABEL: "?f@@YAXPBU.objc_cls_I@@@Z"

void f(I &) {}
// CHECK-LABEL: "?f@@YAXAAUI@@@Z"
// CHECK-LABEL: "?f@@YAXAAU.objc_cls_I@@@Z"

void f(const I &) {}
// CHECK-LABEL: "?f@@YAXABUI@@@Z"
// CHECK-LABEL: "?f@@YAXABU.objc_cls_I@@@Z"

void f(const I &&) {}
// CHECK-LABEL: "?f@@YAX$$QBUI@@@Z"
// CHECK-LABEL: "?f@@YAX$$QBU.objc_cls_I@@@Z"

void g(id) {}
// CHECK-LABEL: "?g@@YAXPAUobjc_object@@@Z"
// CHECK-LABEL: "?g@@YAXPAU.objc_object@@@Z"

void g(id &) {}
// CHECK-LABEL: "?g@@YAXAAPAUobjc_object@@@Z"
// CHECK-LABEL: "?g@@YAXAAPAU.objc_object@@@Z"

void g(const id &) {}
// CHECK-LABEL: "?g@@YAXABQAUobjc_object@@@Z"
// CHECK-LABEL: "?g@@YAXABQAU.objc_object@@@Z"

void g(id &&) {}
// CHECK-LABEL: "?g@@YAX$$QAPAUobjc_object@@@Z"
// CHECK-LABEL: "?g@@YAX$$QAPAU.objc_object@@@Z"

void h(Class) {}
// CHECK-LABEL: "?h@@YAXPAUobjc_class@@@Z"
// CHECK-LABEL: "?h@@YAXPAU.objc_class@@@Z"

void h(Class &) {}
// CHECK-LABEL: "?h@@YAXAAPAUobjc_class@@@Z"
// CHECK-LABEL: "?h@@YAXAAPAU.objc_class@@@Z"

void h(const Class &) {}
// CHECK-LABEL: "?h@@YAXABQAUobjc_class@@@Z"
// CHECK-LABEL: "?h@@YAXABQAU.objc_class@@@Z"

void h(Class &&) {}
// CHECK-LABEL: "?h@@YAX$$QAPAUobjc_class@@@Z"
// CHECK-LABEL: "?h@@YAX$$QAPAU.objc_class@@@Z"

I *i() { return nullptr; }
// CHECK-LABEL: "?i@@YAPAUI@@XZ"
// CHECK-LABEL: "?i@@YAPAU.objc_cls_I@@XZ"

const I *j() { return nullptr; }
// CHECK-LABEL: "?j@@YAPBUI@@XZ"
// CHECK-LABEL: "?j@@YAPBU.objc_cls_I@@XZ"

I &k() { return *kI; }
// CHECK-LABEL: "?k@@YAAAUI@@XZ"
// CHECK-LABEL: "?k@@YAAAU.objc_cls_I@@XZ"

const I &l() { return *kI; }
// CHECK-LABEL: "?l@@YAABUI@@XZ"
// CHECK-LABEL: "?l@@YAABU.objc_cls_I@@XZ"

void m(const id) {}
// CHECK-LABEL: "?m@@YAXQAUobjc_object@@@Z"
// CHECK-LABEL: "?m@@YAXQAU.objc_object@@@Z"

void m(const I *) {}
// CHECK-LABEL: "?m@@YAXPBUI@@@Z"
// CHECK-LABEL: "?m@@YAXPBU.objc_cls_I@@@Z"

void n(SEL) {}
// CHECK-LABEL: "?n@@YAXPAUobjc_selector@@@Z"
// CHECK-LABEL: "?n@@YAXPAU.objc_selector@@@Z"

void n(SEL *) {}
// CHECK-LABEL: "?n@@YAXPAPAUobjc_selector@@@Z"
// CHECK-LABEL: "?n@@YAXPAPAU.objc_selector@@@Z"

void n(const SEL *) {}
// CHECK-LABEL: "?n@@YAXPBQAUobjc_selector@@@Z"
// CHECK-LABEL: "?n@@YAXPBQAU.objc_selector@@@Z"

void n(SEL &) {}
// CHECK-LABEL: "?n@@YAXAAPAUobjc_selector@@@Z"
// CHECK-LABEL: "?n@@YAXAAPAU.objc_selector@@@Z"

void n(const SEL &) {}
// CHECK-LABEL: "?n@@YAXABQAUobjc_selector@@@Z"
// CHECK-LABEL: "?n@@YAXABQAU.objc_selector@@@Z"

void n(SEL &&) {}
// CHECK-LABEL: "?n@@YAX$$QAPAUobjc_selector@@@Z"
// CHECK-LABEL: "?n@@YAX$$QAPAU.objc_selector@@@Z"

struct __declspec(dllexport) s {
struct s &operator=(const struct s &) = delete;

void m(I *) {}
// CHECK-LABEL: "?m@s@@QAAXPAUI@@@Z"
// CHECK-LABEL: "?m@s@@QAAXPAU.objc_cls_I@@@Z"

void m(const I *) {}
// CHECK-LABEL: "?m@s@@QAAXPBUI@@@Z"
// CHECK-LABEL: "?m@s@@QAAXPBU.objc_cls_I@@@Z"

void m(I &) {}
// CHECK-LABEL: "?m@s@@QAAXAAUI@@@Z"
// CHECK-LABEL: "?m@s@@QAAXAAU.objc_cls_I@@@Z"

void m(const I &) {}
// CHECK-LABEL: "?m@s@@QAAXABUI@@@Z"
// CHECK-LABEL: "?m@s@@QAAXABU.objc_cls_I@@@Z"

void m(I &&) {}
// CHECK-LABEL: "?m@s@@QAAX$$QAUI@@@Z"
// CHECK-LABEL: "?m@s@@QAAX$$QAU.objc_cls_I@@@Z"

void m(const I &&) {}
// CHECK-LABEL: "?m@s@@QAAX$$QBUI@@@Z"
// CHECK-LABEL: "?m@s@@QAAX$$QBU.objc_cls_I@@@Z"

void m(id) {}
// CHECK-LABEL: "?m@s@@QAAXPAUobjc_object@@@Z"
// CHECK-LABEL: "?m@s@@QAAXPAU.objc_object@@@Z"

void m(id &) {}
// CHECK-LABEL: "?m@s@@QAAXAAPAUobjc_object@@@Z"
// CHECK-LABEL: "?m@s@@QAAXAAPAU.objc_object@@@Z"

void m(id &&) {}
// CHECK-LABEL: "?m@s@@QAAX$$QAPAUobjc_object@@@Z"
// CHECK-LABEL: "?m@s@@QAAX$$QAPAU.objc_object@@@Z"

void m(const id &) {}
// CHECK-LABEL: "?m@s@@QAAXABQAUobjc_object@@@Z"
// CHECK-LABEL: "?m@s@@QAAXABQAU.objc_object@@@Z"

void m(const id &&) {}
// CHECK-LABEL: "?m@s@@QAAX$$QBQAUobjc_object@@@Z"
// CHECK-LABEL: "?m@s@@QAAX$$QBQAU.objc_object@@@Z"

void m(Class *) {}
// CHECK-LABEL: "?m@s@@QAAXPAPAUobjc_class@@@Z"
// CHECK-LABEL: "?m@s@@QAAXPAPAU.objc_class@@@Z"

void m(const Class *) {}
// CHECK-LABEL: "?m@s@@QAAXPBQAUobjc_class@@@Z"
// CHECK-LABEL: "?m@s@@QAAXPBQAU.objc_class@@@Z"

void m(Class) {}
// CHECK-LABEL: "?m@s@@QAAXPAUobjc_class@@@Z"
// CHECK-LABEL: "?m@s@@QAAXPAU.objc_class@@@Z"

void m(Class &) {}
// CHECK-LABEL: "?m@s@@QAAXAAPAUobjc_class@@@Z"
// CHECK-LABEL: "?m@s@@QAAXAAPAU.objc_class@@@Z"

void m(const Class &) {}
// CHECK-LABEL: "?m@s@@QAAXABQAUobjc_class@@@Z"
// CHECK-LABEL: "?m@s@@QAAXABQAU.objc_class@@@Z"

void m(Class &&) {}
// CHECK-LABEL: "?m@s@@QAAX$$QAPAUobjc_class@@@Z"
// CHECK-LABEL: "?m@s@@QAAX$$QAPAU.objc_class@@@Z"

void m(const Class &&) {}
// CHECK-LABEL: "?m@s@@QAAX$$QBQAUobjc_class@@@Z"
// CHECK-LABEL: "?m@s@@QAAX$$QBQAU.objc_class@@@Z"

void m(SEL) {}
// CHECK-LABEL: "?m@s@@QAAXPAUobjc_selector@@@Z"
// CHECK-LABEL: "?m@s@@QAAXPAU.objc_selector@@@Z"

void m(SEL *) {}
// CHECK-LABEL: "?m@s@@QAAXPAPAUobjc_selector@@@Z"
// CHECK-LABEL: "?m@s@@QAAXPAPAU.objc_selector@@@Z"

void m(const SEL *) {}
// CHECK-LABEL: "?m@s@@QAAXPBQAUobjc_selector@@@Z"
// CHECK-LABEL: "?m@s@@QAAXPBQAU.objc_selector@@@Z"

void m(SEL &) {}
// CHECK-LABEL: "?m@s@@QAAXAAPAUobjc_selector@@@Z"
// CHECK-LABEL: "?m@s@@QAAXAAPAU.objc_selector@@@Z"

void m(const SEL &) {}
// CHECK-LABEL: "?m@s@@QAAXABQAUobjc_selector@@@Z"
// CHECK-LABEL: "?m@s@@QAAXABQAU.objc_selector@@@Z"

void m(SEL &&) {}
// CHECK-LABEL: "?m@s@@QAAX$$QAPAUobjc_selector@@@Z"
// CHECK-LABEL: "?m@s@@QAAX$$QAPAU.objc_selector@@@Z"

void m(const SEL &&) {}
// CHECK-LABEL: "?m@s@@QAAX$$QBQAUobjc_selector@@@Z"
// CHECK-LABEL: "?m@s@@QAAX$$QBQAU.objc_selector@@@Z"
};

template <typename T>
Expand All @@ -179,14 +179,14 @@ void m(const SEL &&) {}
};

template struct t<id>;
// CHECK-LABEL: "??0?$t@PAUobjc_object@@@@QAA@XZ"
// CHECK-LABEL: "??0?$t@PAU.objc_object@@@@QAA@XZ"

template struct t<remove_pointer<id>::type>;
// CHECK-LABEL: "??0?$t@Uobjc_object@@@@QAA@XZ"
// CHECK-LABEL: "??0?$t@U.objc_object@@@@QAA@XZ"

template struct t<SEL>;
// CHECK-LABEL: "??0?$t@PAUobjc_selector@@@@QAA@XZ"
// CHECK-LABEL: "??0?$t@PAU.objc_selector@@@@QAA@XZ"

template struct t<remove_pointer<SEL>::type>;
// CHECK-LABEL: "??0?$t@Uobjc_selector@@@@QAA@XZ"
// CHECK-LABEL: "??0?$t@U.objc_selector@@@@QAA@XZ"