This is an archive of the discontinued LLVM Phabricator instance.

[clang] add APValue type check in `TryPrintAsStringLiteral`
ClosedPublic

Authored by inclyc on Aug 8 2022, 10:17 PM.

Details

Summary

Fixes https://github.com/llvm/llvm-project/issues/57013

https://reviews.llvm.org/D115031 improved printing of non-type template
parameter args. But checking if the end of Inits is 0 without checking
if APValue is an integer, causes clang to segfault. This patch adds
the code to check the type. (May not be a proper bugfix.)

Diff Detail

Event Timeline

inclyc created this revision.Aug 8 2022, 10:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2022, 10:17 PM
inclyc published this revision for review.Aug 8 2022, 10:22 PM
inclyc edited the summary of this revision. (Show Details)
Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2022, 10:22 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
shafik added inline comments.Aug 8 2022, 10:29 PM
clang/lib/AST/APValue.cpp
660

I believe to be fully correct we also need to add:

if (!Val.isInt())
  return false;

I wonder if APValue needs a member function to verify the underlying type of an Array

inclyc updated this revision to Diff 451049.Aug 8 2022, 10:36 PM
inclyc edited the summary of this revision. (Show Details)

Address reviewer's comments

Can you add test coverage for these changes?

inclyc updated this revision to Diff 451195.Aug 9 2022, 10:13 AM

address comments

inclyc added inline comments.Aug 9 2022, 10:19 AM
clang/test/SemaCXX/try-print-as-string-literal-type-check.cpp
8

The ArrayRef<APValue> Inits points to here does not ends with Int, so !Inits.back().getInt() gets assertion failed.

lichray accepted this revision.Aug 9 2022, 12:25 PM

LGTM

This revision is now accepted and ready to land.Aug 9 2022, 12:25 PM
aaron.ballman accepted this revision.Aug 9 2022, 12:49 PM

LGTM!

I think this change should be backported to Clang 15.x since the breakage happened in that release and the fix is pretty straightforward. After this lands, I'll file the issue for it to get that process started. Thank you for the fix!

This revision was landed with ongoing or failed builds.Aug 9 2022, 5:43 PM
This revision was automatically updated to reflect the committed changes.