[cfe-dev] Objective-C Runtime specific code in CGObjC.cpp
Nat! via cfe-dev
cfe-dev at lists.llvm.org
Tue Mar 19 14:04:35 PDT 2019
In clang there is a separation between the Objective-C language and the
runtime implementation. Code that is specific to the runtime should be
in one of the various Objective-C runtime subclasses like
"CGObjCGNU.cpp" and "CGObjCMac.cpp".
It occurred to me today, that this separation is not adhered to very
well. And it seems to be getting worse (IMO).
Here's one simple example of many, on line 2534:
https://github.com/llvm/llvm-project/blob/master/clang/lib/CodeGen/CGObjC.cpp#L2534
```
/// Allocate the given objc object.
/// call i8* \@objc_alloc(i8* %value)
llvm::Value *CodeGenFunction::EmitObjCAlloc(llvm::Value *value,
llvm::Type *resultType) {
return emitObjCValueOperation(*this, value, resultType,
CGM.getObjCEntrypoints().objc_alloc,
"objc_alloc");
}
```
This is basically hardwired to the Apple runtime. If any runtime wants
to partake in this codepath (*) , it is forced not only to use Apple's
naming but also its parameter scheme (you can't have an extra parameter
for instance).
Second the llvm::type of the function is also defined (I believe), as
the resulting value is then cached in "getObjCEntryPoints" which
specifies if something is a llvm::InlineAsm or a llvm::Constant. That
also seems runtime specific.
I'd expect code like CodeGenFunction::EmitObjCAlloc to be in
"CGObjCMac.cpp" and declared overridable in "CGObjCRuntime.h".
Ciao
Nat!
(*) shouldUseRuntimeFunctionsForAlloc, which is off by default for all
non-Apple runtimes.
More information about the cfe-dev
mailing list