This is an archive of the discontinued LLVM Phabricator instance.

AMDGPU: Fix broken and permissive handling of printf format strings
ClosedPublic

Authored by arsenm on Dec 22 2022, 8:56 AM.

Details

Reviewers
sameerds
rampitec
vikramRH
yaxunl
cdevadas
Group Reviewers
Restricted Project
Summary

This was completely broken with opaque pointers because it was
specifically looking for a constant expression with the global
variable as the first operand. Strip casts like normal, and properly
validate all of the restrictions rather than silently ignoring any
unhandled cases. Also be stricter that we aren't calling into some
unresolved or non-constant format string.

Also converts the test to opaque pointers and generated tests. There's
more broken initializer handling for strings inside the format string
processing too, but there's just no test coverage for this at all.

Diff Detail

Event Timeline

arsenm created this revision.Dec 22 2022, 8:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 22 2022, 8:56 AM
arsenm requested review of this revision.Dec 22 2022, 8:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 22 2022, 8:56 AM
Herald added a subscriber: wdng. · View Herald Transcript

This pass is used only by OpenCL on AMDGPU. We don't really need to handle errors at the LLVM IR level, since Clang will have already validated the printf call under the OpenCL spec. It's sufficient to just return -1 on anything invalid according to OpenCL printf spec.

If we really should keep this check, can you please make sure it passes internal OpenCL builds on AMDGPU?

arsenm added a comment.Jan 4 2023, 4:51 AM

This pass is used only by OpenCL on AMDGPU. We don't really need to handle errors at the LLVM IR level, since Clang will have already validated the printf call under the OpenCL spec. It's sufficient to just return -1 on anything invalid according to OpenCL printf spec.

This is operating on IR, it needs to handle the whole IR. This isn't diagnosing end user errors, but everything that could have happened to the IR in and after the emission in clang. It needs to validate it's handling only exactly what's expected from clang.

If we really should keep this check, can you please make sure it passes internal OpenCL builds on AMDGPU?

Yes, but the printf testing is clearly not worth anything since it didn't catch any of these opaque pointer issues

This pass is used only by OpenCL on AMDGPU. We don't really need to handle errors at the LLVM IR level, since Clang will have already validated the printf call under the OpenCL spec. It's sufficient to just return -1 on anything invalid according to OpenCL printf spec.

If we really should keep this check, can you please make sure it passes internal OpenCL builds on AMDGPU?

Passed

sameerds accepted this revision.Jan 4 2023, 10:11 PM
This revision is now accepted and ready to land.Jan 4 2023, 10:11 PM