Skip to content

Commit

Permalink
Add Windows support for the GNUstep Objective-C ABI V2.
Browse files Browse the repository at this point in the history
Summary:
Introduces funclet-based unwinding for Objective-C and fixes an issue
where global blocks can't have their isa pointers initialised on
Windows.

After discussion with Dustin, this changes the name mangling of
Objective-C types to prevent a C++ catch statement of type struct X*
from catching an Objective-C object of type X*.

Reviewers: rjmccall, DHowett-MSFT

Reviewed By: rjmccall, DHowett-MSFT

Subscribers: mgrang, mstorsjo, smeenai, cfe-commits

Differential Revision: https://reviews.llvm.org/D50144

llvm-svn: 339428
  • Loading branch information
David Chisnall committed Aug 10, 2018
1 parent bebcd6f commit 93ce018
Show file tree
Hide file tree
Showing 14 changed files with 363 additions and 179 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Driver/Options.td
Expand Up @@ -1488,7 +1488,7 @@ def fobjc_weak : Flag<["-"], "fobjc-weak">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Enable ARC-style weak references in Objective-C">;

// Objective-C ABI options.
def fobjc_runtime_EQ : Joined<["-"], "fobjc-runtime=">, Group<f_Group>, Flags<[CC1Option]>,
def fobjc_runtime_EQ : Joined<["-"], "fobjc-runtime=">, Group<f_Group>, Flags<[CC1Option, CoreOption]>,
HelpText<"Specify the target Objective-C runtime kind and version">;
def fobjc_abi_version_EQ : Joined<["-"], "fobjc-abi-version=">, Group<f_Group>;
def fobjc_nonfragile_abi_version_EQ : Joined<["-"], "fobjc-nonfragile-abi-version=">, Group<f_Group>;
Expand Down
19 changes: 10 additions & 9 deletions clang/lib/AST/MicrosoftMangle.cpp
Expand Up @@ -445,7 +445,7 @@ void MicrosoftCXXNameMangler::mangle(const NamedDecl *D, StringRef Prefix) {
mangleFunctionEncoding(FD, Context.shouldMangleDeclName(FD));
else if (const VarDecl *VD = dyn_cast<VarDecl>(D))
mangleVariableEncoding(VD);
else
else if (!isa<ObjCInterfaceDecl>(D))
llvm_unreachable("Tried to mangle unexpected NamedDecl!");
}

Expand Down Expand Up @@ -1884,13 +1884,13 @@ void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers,
llvm_unreachable("placeholder types shouldn't get to name mangling");

case BuiltinType::ObjCId:
mangleArtificalTagType(TTK_Struct, "objc_object");
mangleArtificalTagType(TTK_Struct, ".objc_object");
break;
case BuiltinType::ObjCClass:
mangleArtificalTagType(TTK_Struct, "objc_class");
mangleArtificalTagType(TTK_Struct, ".objc_class");
break;
case BuiltinType::ObjCSel:
mangleArtificalTagType(TTK_Struct, "objc_selector");
mangleArtificalTagType(TTK_Struct, ".objc_selector");
break;

#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
Expand Down Expand Up @@ -2570,9 +2570,10 @@ void MicrosoftCXXNameMangler::mangleType(const DependentAddressSpaceType *T,

void MicrosoftCXXNameMangler::mangleType(const ObjCInterfaceType *T, Qualifiers,
SourceRange) {
// ObjC interfaces have structs underlying them.
// ObjC interfaces are mangled as if they were structs with a name that is
// not a valid C/C++ identifier
mangleTagTypeKind(TTK_Struct);
mangleName(T->getDecl());
mangle(T->getDecl(), ".objc_cls_");
}

void MicrosoftCXXNameMangler::mangleType(const ObjCObjectType *T, Qualifiers,
Expand All @@ -2590,11 +2591,11 @@ void MicrosoftCXXNameMangler::mangleType(const ObjCObjectType *T, Qualifiers,

Out << "?$";
if (T->isObjCId())
mangleSourceName("objc_object");
mangleSourceName(".objc_object");
else if (T->isObjCClass())
mangleSourceName("objc_class");
mangleSourceName(".objc_class");
else
mangleSourceName(T->getInterface()->getName());
mangleSourceName((".objc_cls_" + T->getInterface()->getName()).str());

for (const auto &Q : T->quals())
mangleObjCProtocol(Q);
Expand Down
7 changes: 6 additions & 1 deletion clang/lib/CodeGen/CGException.cpp
Expand Up @@ -1829,7 +1829,7 @@ void CodeGenFunction::startOutlinedSEHHelper(CodeGenFunction &ParentCGF,
SmallString<128> Name;
{
llvm::raw_svector_ostream OS(Name);
const FunctionDecl *ParentSEHFn = ParentCGF.CurSEHParent;
const NamedDecl *ParentSEHFn = ParentCGF.CurSEHParent;
assert(ParentSEHFn && "No CurSEHParent!");
MangleContext &Mangler = CGM.getCXXABI().getMangleContext();
if (IsFilter)
Expand Down Expand Up @@ -1972,6 +1972,11 @@ llvm::Value *CodeGenFunction::EmitSEHAbnormalTermination() {
return Builder.CreateZExt(&*AI, Int32Ty);
}

void CodeGenFunction::pushSEHCleanup(CleanupKind Kind,
llvm::Function *FinallyFunc) {
EHStack.pushCleanup<PerformSEHFinally>(Kind, FinallyFunc);
}

void CodeGenFunction::EnterSEHTryStmt(const SEHTryStmt &S) {
CodeGenFunction HelperCGF(CGM, /*suppressNewContext=*/true);
if (const SEHFinallyStmt *Finally = S.getFinallyHandler()) {
Expand Down

0 comments on commit 93ce018

Please sign in to comment.