This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Fix the new driver crashing when using '-fsyntax-only'
ClosedPublic

Authored by jhuber6 on Sep 1 2022, 3:09 PM.

Details

Summary

The new driver currently crashses when attempting to use the
'-fsyntax-only' option. This is because the option causes all output to
be given the `TY_Nothing' type which should signal the end of the
pipeline. The new driver was not treating this correctly and attempting
to use empty input. This patch fixes the handling so we do not attempt
to continue when the input is nothing.

One concession is that we must now check when generating the arguments
for Clang if the input is of 'TY_Nothing'. This is because the new
driver will only create code if the device code is a dependency on the
host, creating the output without the dependency would require a
complete rewrite of the logic as we do not maintain any state between
calls to 'BuildOffloadingActions' so I believe this is the most
straightforward method.

Diff Detail

Event Timeline

jhuber6 created this revision.Sep 1 2022, 3:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 1 2022, 3:09 PM
jhuber6 requested review of this revision.Sep 1 2022, 3:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 1 2022, 3:09 PM
tra added a comment.Sep 1 2022, 3:25 PM

Does this patch obviate D133133 or is it purely for the new driver functionality?

Does this patch obviate D133133 or is it purely for the new driver functionality?

If the intent of that patch was to prevent it from emitting an error with -o when -fsyntax-only is used then this is not a replacement. This is just a new driver specific change to the logic that correctly handles TY_Nothing output.

tra added a comment.Sep 1 2022, 4:03 PM

OK. I'm going to land it then.

clang/lib/Driver/Driver.cpp
4388–4390

any_of(A->getType() == types::TY_Nothing) looks like a rather indirect way to infer that we have -fsyntax-only. Would there be any other legitimate case when we'd have Ty_Nothing actions?

4395

Assuming that we're guaranteed that all actions produce no outputs, can we just pass an empty array if -fsyntax-only is specified?

clang/lib/Driver/ToolChains/Clang.cpp
4499–4500

.. and if we don't propagate no-output actions, there would be no need to filter them here.

jhuber6 added inline comments.Sep 1 2022, 4:45 PM
clang/lib/Driver/Driver.cpp
4388–4390

This is more or less how the existing pipeline handles it. We shouldn't propagate TY_Nothing attributes regardless, -fsyntax-only just happens to create them. So this is more correct I believe.

4395

No, this is required to make the device actions be generated. The old driver manually added device actions to the final action list, while the new driver adds them as host dependencies. I prefer the new method as it requires no internal state so it can just be a simple function like here.

clang/lib/Driver/ToolChains/Clang.cpp
4499–4500

Without that we would need to change the logic to append to the final action list directly, which would be an enormous hack given the current architecture of the new driver. FWIW I think this is a valid operation regardless, this didn't have a good failure mode in the first place, it just crashed on some assertion later if you did it. This at least makes sure that we'll get some "no input" error message AFAIK.

tra accepted this revision.Sep 6 2022, 2:53 PM
tra added inline comments.
clang/lib/Driver/Driver.cpp
4388–4390

OK. Would it make sense to add a helper method with descriptive name? E.g. hasValidOutput so future readers do not have to guess what we're doing and why.

This revision is now accepted and ready to land.Sep 6 2022, 2:53 PM