This is an archive of the discontinued LLVM Phabricator instance.

[clang] Fix a nullptr-access crash in CheckTemplateArgument.
ClosedPublic

Authored by hokein on Sep 19 2022, 6:13 AM.

Details

Summary

It is possible that we can pass a null ParamType to
CheckNonTypeTemplateParameter -- the ParamType var can be reset to a null
type on Line 6940, and the followed bailout if is not entered.

Diff Detail

Event Timeline

hokein created this revision.Sep 19 2022, 6:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 19 2022, 6:13 AM
hokein requested review of this revision.Sep 19 2022, 6:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 19 2022, 6:13 AM
adamcz accepted this revision.Sep 19 2022, 6:32 AM
adamcz added inline comments.
clang/lib/Sema/SemaTemplate.cpp
6965

So this can only happen when Result is TDK_AlreadyDiagnosed above, right? In that case, I would handle such case explicitly in the code above, like:
if (Result == TDK_AlreadyDiagnosed) return ExprError();
else if (Result != TDK_Success) { ... }
Seems like it would be more readable.

However, I am definitely not opposed to keeping this check here as well, in case there are other ways to get into this situation.

This revision is now accepted and ready to land.Sep 19 2022, 6:32 AM
hokein updated this revision to Diff 461260.Sep 19 2022, 10:21 AM
hokein marked an inline comment as done.

address review comment.

clang/lib/Sema/SemaTemplate.cpp
6965

right. I think either of them works, switched to your version.

This revision was landed with ongoing or failed builds.Sep 19 2022, 10:21 AM
This revision was automatically updated to reflect the committed changes.