================
@@ -1035,10 +1182,48 @@ bool createParameters(NewFunction &ExtractedFunc,
TypeInfo.addConst();
}
}
+
+ // C has no references. A parameter that would otherwise need one
+ // becomes a real pointer instead: the call site takes the address of
+ // the original variable explicitly, and every use of it in the
+ // copied-out body is rewritten into a dereference (see
+ // NewFunction::getFuncBody). Array types are the exception: they decay
+ // to a pointer on their own wherever they're used, so no rewriting or
+ // address-of is needed for them at all -- except that TypeInfo itself
+ // must be decayed too (NewFunction::Parameter::render() has no special
+ // case for array declarator syntax, so leaving it as an array type
+ // would print as the uncompilable `int[5] name`).
+ if (Kind == ParamPassKind::Reference && !LangOpts.CPlusPlus) {
+ if (TypeInfo->isArrayType()) {
+ // A decayed pointer no longer reports the array's own size,
+ // alignment, or type: bail out rather than silently break a
+ // sizeof/alignof/typeof (or similar) on it.
+ if (DeclInfo.HasUnsafeTypeQueryUseInZone)
+ return false;
+ TypeInfo = Context.getArrayDecayedType(TypeInfo);
+ Kind = ParamPassKind::Value;
+ } else {
+ // Bail out rather than rewrite a use whose location can't be
+ // mapped back to a single, unambiguous spot in the source (e.g.
+ // one produced by macro expansion).
+ if (llvm::any_of(
+ DeclInfo.ZoneOccurrences,
+ [](const CapturedZoneInfo::DeclInformation::Occurrence &O) {
+ return O.Loc.isMacroID();
----------------
ArcsinX wrote:
It guess we need to check `O.DotLoc` here, because `DotLoc` also can be in
macro while `Loc` is not.
E.g.
```cpp
#define DOT .
struct S {
int X;
};
void f() {
S s;
s DOT X = 1;
}
```
https://github.com/llvm/llvm-project/pull/228465
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits