[Sema] Fix crash on __fp16 parameters in template instantiations
authorIlya Biryukov <ibiryukov@google.com>
Tue, 21 Mar 2023 13:06:45 +0000 (14:06 +0100)
committerIlya Biryukov <ibiryukov@google.com>
Tue, 21 Mar 2023 13:06:46 +0000 (14:06 +0100)
commit282cae0b9a602267ad7ef622f770066491332a11
tree31a42a6bd1a39c78223b15f5df7145b45d2a2e46
parenta6a788bdfb39cbf66e7196a39785d848ce714338
[Sema] Fix crash on __fp16 parameters in template instantiations

Fixes #61441.

Currently, Clang stores `nullptr` in the parameter lists inside
`FunctionProtoTypeLoc` if `__fp16` is used without pointer qualifiers.

Any code path that calls `Declarator::setInvalidType()` before
`GetFullTypeForDeclarator` will lead to the same problem downstream.

The relevant code is:
```cpp
if (D.isInvalidType())
  return Context.getTrivialTypeSourceInfo(T);

return GetTypeSourceInfoForDeclarator(state, T, TInfo);
```

`GetTypeSourceInfoForDeclarator` sets the parameter `Decl`, but we can't
call it when `isInvalidType() == true` as this causes other assertion
failures that seem harder to fix.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D146426
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/test/SemaCXX/GH61441.cpp [new file with mode: 0644]