This is an archive of the discontinued LLVM Phabricator instance.

Disallow fbasic-block-sections on non-ELF, non-x86 targets.
ClosedPublic

Authored by snehasish on Sep 9 2020, 5:57 PM.

Details

Summary

Basic block sections is untested on other platforms and binary formats apart from x86,elf. This patch silently drops the flag if the platform and binary format is not compatible.

Diff Detail

Event Timeline

snehasish created this revision.Sep 9 2020, 5:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 9 2020, 5:57 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
snehasish requested review of this revision.Sep 9 2020, 5:57 PM
rahmanl accepted this revision.Sep 9 2020, 6:23 PM
rahmanl added inline comments.
clang/test/Driver/fbasic-block-sections.c
12

nit, ignore if you want:
CHECK-NOOPT-NOT sounds like double negative? How about using CHECK-OPT-NONX86 or CHECK-OPT-ARM for the check prefix?

This revision is now accepted and ready to land.Sep 9 2020, 6:23 PM
snehasish updated this revision to Diff 290863.Sep 9 2020, 7:24 PM

Specify triple for driver tests, address comments.

MaskRay added a subscriber: MaskRay.Sep 9 2020, 7:36 PM
MaskRay added inline comments.
clang/test/Driver/fbasic-block-sections.c
1–6

Consider dropping -linux-gnu because they are insignificant.

The code applies to generic ELF.

MaskRay requested changes to this revision.Sep 9 2020, 7:37 PM
MaskRay added inline comments.
clang/test/Driver/fbasic-block-sections.c
12

CHECK-TRIPLE should check the diagnostic instead.

This revision now requires changes to proceed.Sep 9 2020, 7:37 PM
MaskRay added inline comments.Sep 9 2020, 7:38 PM
clang/lib/Driver/ToolChains/Clang.cpp
4892

This should be an error

clang/test/Driver/fbasic-block-sections.c
5

%clang -### -> not %clang -fsyntax-only

snehasish updated this revision to Diff 290867.Sep 9 2020, 8:52 PM

Update test based on review comments.

  • Use diag::err instead of warn.
  • Drop linux-gnu from the triple for the default test.
  • Check for the presence of the diagnostic message.
snehasish marked 3 inline comments as done.Sep 9 2020, 8:58 PM

Thanks for the quick review @MaskRay, PTAL.

clang/lib/Driver/ToolChains/Clang.cpp
4892

Sure, can you provide a reference/guidance for when err vs warn is appropriate for driver checks? Most of the code in this file uses err but there are some cases of warn being used.

clang/test/Driver/fbasic-block-sections.c
5

What I really want to check for is the absence of the flag for the particular triple. Using -fsyntax-only means that the cc1 args are not emitted. I've added a check for the diagnostic message but retained -### so that I can keep the check for the absence of -fbasic-block-sections=all.

MaskRay added inline comments.Sep 9 2020, 10:09 PM
clang/lib/Driver/ToolChains/Clang.cpp
4892

I think a warning is suitable for some GCC specific optimization options where a clang port either does not make sense or is not very necessary. This only applies to very common options which ease porting to clang. For clang specific optimizations, especially these with complex setup, I think an error is more useful.

clang/test/Driver/fbasic-block-sections.c
5

Then you can switch to -c

The idea of not %clang is that it makes things clear that it is an error.

12

The NOT pattern is not useful when testing an error.

snehasish marked an inline comment as done.

Update test to use not tool and -c flag.

  • Use the not tool to indicate failure is expected.
  • Use -c instead of -### for failing invocations.
snehasish marked 4 inline comments as done.Sep 10 2020, 12:04 AM

Thanks for explaining the rationale, PTAL.

MaskRay accepted this revision.Sep 10 2020, 12:08 AM

Looks great!

This revision is now accepted and ready to land.Sep 10 2020, 12:08 AM
This revision was landed with ongoing or failed builds.Sep 10 2020, 12:20 AM
This revision was automatically updated to reflect the committed changes.