Fixed: https://github.com/llvm/llvm-project/issues/62408
setInvalidDecl for invalid CXXDeductionGuideDecl to
avoid crashes during semantic analysis.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Thank you for the fix.
I have some questions, why don't we always call CheckDeductionGuideDeclarator when calling CXXDeductionGuideDecl::Create, I felt like perhaps CheckDeductionGuideDeclarator should be rolled into CXXDeductionGuideDecl::Create but then I noticed they are not paired up in other locations.
CC @rsmith
I wonder if there are any cases where the "deduction guide" is so broken that we shouldn't be creating a CXXDeductionGuideDecl at all. For example, if there's no trailing return type, then the declaration is syntactically invalid (and looks more like a constructor than a deduction guide), and it's not clear to me whether creating a CXXDeductionGuideDecl really makes sense.
CXXDeductionGuideDecl::Create is the low-level AST primitive for creating a CXXDeductionGuideDecl. The responsibility for validating the declaration and issuing diagnostics doesn't belong at that level, it belongs in Sema. The other callers are:
- When Sema creates an implicit deduction guide from a constructor. In this case Sema knows it's valid by construction.
- When Sema instantiates a deduction guide. In this case Sema knows it's valid because the template was.
clang/lib/Sema/SemaDecl.cpp | ||
---|---|---|
9201–9202 | This is reversed from the normal Clang convention (where true indicates that an error was produced). | |
9204 | Use auto here. | |
clang/lib/Sema/SemaDeclCXX.cpp | ||
11140–11143 | Can we just return immediately here? I don't see a reason to keep going -- this error may well indicate that the developer didn't actually mean to declare a deduction guide in the first place, so the diagnostic on a function body below is likely to not be useful. | |
11194–11195 | Should we return that we had an error after this one too? |
clang/lib/Sema/SemaDeclCXX.cpp | ||
---|---|---|
11194–11195 | if D.isFunctionDefinition(), we can still create valid deduction guide. I think keeping it can avoid lots of meaningless error later. |
clang/lib/Sema/SemaDeclCXX.cpp | ||
---|---|---|
11140–11143 | NIT: You can also just do return Diag(...) here and in other places. This is equal to return true. |
LGTM aside from a request for a comment.
clang/lib/Sema/SemaDeclCXX.cpp | ||
---|---|---|
11194–11195 | I think it's worth leaving that as a comment in the code so folks know it's done on purpose and why. |
Hi @HerrCai0907, this change is failing on the PS4 linux and PS5 Windows bot. Can you take a look? I'm guessing these failures are likely due to the PS4/PS5 target defaulting to a different C/C++ standard than the rest of clang.
https://lab.llvm.org/buildbot/#/builders/139/builds/41248
https://lab.llvm.org/buildbot/#/builders/216/builds/21637
The build bot failures have been going for a while now so I've had to revert this until the author can address them, my apologies.
This is reversed from the normal Clang convention (where true indicates that an error was produced).