This is an archive of the discontinued LLVM Phabricator instance.

[SimplifyLibCalls] Pre-commit test case showing bug with wide char support
ClosedPublic

Authored by bjope on Oct 5 2022, 5:44 AM.

Details

Summary

The ValueTracking support for getting the string length of a wchar_t
string (e.g. using wcslen) seem to be having some bugs.

Problem I've seen is that llvm::getConstantDataArrayInfo is taking
both a "ElementSize" argument (basically indicating size of a
char/element in bits) and an "Offset" which afaict is an offset
in the unit "number of elements". Then it also use
stripAndAccumulateConstantOffsets to get a "StartIdx" which afaict
is calculated in bytes. The returned Slice.Length is based on
arithmetics that add/subtract variables that are having different
units (bytes vs elements). Most notably I think the "StartIdx" must
be scaled using the "ElementSize" to get correct results.

This patch just adds a new test case showing that we get a wrong
result when doing wcslen(x + c). The actual fix to the above problem
will be done in a follow up commit.

Diff Detail

Event Timeline

bjope created this revision.Oct 5 2022, 5:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 5 2022, 5:44 AM
bjope requested review of this revision.Oct 5 2022, 5:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 5 2022, 5:44 AM
nikic accepted this revision.Oct 5 2022, 6:09 AM
nikic added a subscriber: nikic.

LG, though I would personally add this to one of the existing wcslen tests.

llvm/test/Transforms/InstCombine/wcslen-7.ll
15

Drop dso_local

This revision is now accepted and ready to land.Oct 5 2022, 6:09 AM
bjope added a comment.Oct 5 2022, 6:58 AM

LG, though I would personally add this to one of the existing wcslen tests.

Right, I'll move it (I think adding it to wcslen-1.ll should be fine, that seem to be standard tests to see that the simplifications work with wchar_size=4).

bjope updated this revision to Diff 465791.Oct 6 2022, 11:05 AM

Moved new test case to wcslen-1.ll.