This is an archive of the discontinued LLVM Phabricator instance.

[OpenCL] Do not include default header for preprocessor output as input
ClosedPublic

Authored by yaxunl on Jun 23 2021, 11:03 AM.

Details

Summary

When clang driver is used with -save-temps to compile OpenCL program,
clang driver first launches clang -cc1 -E to generate preprocessor expansion output,
then launches clang -cc1 with the generated preprocessor expansion output as input
to generate LLVM IR.

Currently clang by default passes "-finclude-default-header" "-fdeclare-opencl-builtins"
in both steps, which causes default header included again in the second step, which
causes error.

This patch let clang not to include default header when input type is preprocessor expansion
output, which fixes the issue.

Diff Detail

Event Timeline

yaxunl created this revision.Jun 23 2021, 11:03 AM
yaxunl requested review of this revision.Jun 23 2021, 11:03 AM

I am not quite sure about whether "-fdeclare-opencl-builtins" should be kept when input is preprocessor output. Suggestions? Thanks.

I am not quite sure about whether "-fdeclare-opencl-builtins" should be kept when input is preprocessor output. Suggestions? Thanks.

The question is that whether those builtins declared through "-fdeclare-opencl-builtins" will be in preprocessor expansion output. It seems not. If so, we still need "-fdeclare-opencl-builtins" when input type is preprocessor expansion output.

LGTM! Thanks

I agree we should have the same behavior for both options. Technically -finclude-default-header could be added in both steps but it is only effective in parsing the sources and does nothing otherwise. But it seems cleaner to align it with the header include option.

Anastasia accepted this revision.Jun 24 2021, 10:43 AM
This revision is now accepted and ready to land.Jun 24 2021, 10:43 AM
This revision was landed with ongoing or failed builds.Jun 25 2021, 7:29 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJun 25 2021, 7:29 AM
Herald added a subscriber: ldrumm. · View Herald Transcript