================
@@ -368,6 +368,14 @@ static FunctionProtoTypeLoc getPrototypeLoc(Expr *Fn) {
   }
 
   if (auto F = Target.getAs<FunctionProtoTypeLoc>()) {
+    // In some edge cases the AST can contain a "trivial" FunctionProtoTypeLoc
+    // which has null parameters. Avoid these as they don't contain useful
+    // information.
+    for (const auto *Param : F.getParams()) {
----------------
HighCommander4 wrote:

My impression from having read some of the related code is that it's a known 
deficiency that having null parameters can sometimes happen.

`TypeLoc` has a method named 
[`initialize()`](https://searchfox.org/llvm/rev/269c29ae67e54bd3243535a7c58d0f30d1eb9036/clang/include/clang/AST/TypeLoc.h#201),
 which is described as follows:

```c++
  /// Initializes this to state that every location in this
  /// type is the given location.
  ///
  /// This method exists to provide a simple transition for code that
  /// relies on location-less types.
  void initialize(ASTContext &Context, SourceLocation Loc) const {
```

The implementation of `initialize` for `FunctionTypeLoc` [does set the 
parameters to 
null](https://searchfox.org/llvm/rev/269c29ae67e54bd3243535a7c58d0f30d1eb9036/clang/include/clang/AST/TypeLoc.h#1579).

And there are various places in the code where we call `initialize`. In 
addition to the `noreturn` scenario exercised in this patch's testcase, which 
will be improved in https://github.com/llvm/llvm-project/pull/143143, another 
notable call site is 
[`ASTContext::getTrivialTypeSourceInfo`](https://searchfox.org/llvm/rev/269c29ae67e54bd3243535a7c58d0f30d1eb9036/clang/lib/AST/ASTContext.cpp#3132).
 That in turn has [many 
callers](https://searchfox.org/llvm/search?q=symbol:_ZNK5clang10ASTContext24getTrivialTypeSourceInfoENS_8QualTypeENS_14SourceLocationE&redirect=false),
 including [this 
one](https://searchfox.org/llvm/rev/269c29ae67e54bd3243535a7c58d0f30d1eb9036/clang/lib/Sema/SemaType.cpp#5679)
 used to handle an invalid declarator.

https://github.com/llvm/llvm-project/pull/143087
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to