This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Do not crash when an invalid offload architecture is set
ClosedPublic

Authored by jhuber6 on Oct 12 2022, 10:05 AM.

Details

Summary

If an invalid architecture is set we currently return an empty string.
This will cause the offloading toolchain to continue to be built and
hit an assertion elsewhere due to the invalid architecture. This patch
fixes that so we now correctly exit.

Diff Detail

Event Timeline

jhuber6 created this revision.Oct 12 2022, 10:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 12 2022, 10:05 AM
jhuber6 requested review of this revision.Oct 12 2022, 10:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 12 2022, 10:05 AM
jhuber6 updated this revision to Diff 467188.Oct 12 2022, 10:29 AM

Fix missing None return on HIP.

tra accepted this revision.Oct 12 2022, 10:50 AM

LGTM with few nits.

clang/lib/Driver/Driver.cpp
4194

Nit. Optional is fine, but we could've just checked returned value for Arch.empty().

4288

Nit: do we need explicit StringRef() here? If implicit type conversion does not work, we could use Arch.equals("all").
The current code is fine, but it does stick out a bit and makes me wonder if there's something interesting going on there.

This revision is now accepted and ready to land.Oct 12 2022, 10:50 AM
jhuber6 added inline comments.Oct 12 2022, 10:53 AM
clang/lib/Driver/Driver.cpp
4194

Probably the better option. I originally used Optional for the implicit boolean conversion, but I don't think it'll make the code that much more complicated.

4288

You're right, previously this used Arg-getValue() but then when it changed to llvm::split it got converted to a StringRef so this can be updated now. Thanks for pointing it out.

jhuber6 updated this revision to Diff 467199.Oct 12 2022, 11:01 AM

Making suggested changes.

tra accepted this revision.Oct 12 2022, 11:09 AM
tra added inline comments.
clang/lib/Driver/Driver.cpp
4211

This can be undone now, too.

4224

ditto.

4293–4296

Nit: we could save one line here:

if(ArchStr.empty()) 
  return Archs;
Archs.erase(ArchStr);
jhuber6 updated this revision to Diff 467204.Oct 12 2022, 11:11 AM

Making suggested changes, Early exists is part of the LLVM style so it's definitely better.

tra accepted this revision.Oct 12 2022, 11:22 AM