| Issue |
238911
|
| Summary |
Blocks' `getSignatureAsWritten()`: surprising behavior with parameterless blocks
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
dougsonos
|
Consider the block: `^int { return 1; }`
Would we expect this to have a function prototype, and with what signature?
`BD->getSignatureAsWritten()->getType()` returns `BuiltinType 'int'` in C++, and `FunctionNoProtoType 'int ()'` in C.
LLM-generated analysis (lightly edited by me):
Why it's intentional: the comment in `ActOnBlockArguments` says that if `GetTypeForDeclarator` synthesized the function prototype, Sema doesn't save it "as part of the written signature". For `^int { ... }` the user wrote only a return type. Sema therefore replaces the stored `TypeSourceInfo` with the `int` return-type loc, so "signature as written" is literally what was written. (`BlockDecl::getFunctionEffects()` already relies on this, since it guards with `getAs<FunctionProtoType>()`.)
Where it's inconsistent:
- Misleading name: `getSignatureAsWritten()` returns something that isn't a function type for these blocks. Every caller has to know that.
- C and C++ differ: the synthesized-signature check only matches `FunctionProtoTypeLoc`. In C++ `^int {}` goes through that path and is stripped to `int`. In C the synthesized type is a `FunctionNoProtoType`, so it isn't stripped, and the stored signature is the fake `int ()` that the user never wrote. The same code gives two different "as written" results depending on language, and I suspect the C case is an oversight in the `FunctionProtoTypeLoc` check rather than a deliberate choice.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs