This is an archive of the discontinued LLVM Phabricator instance.

[RFC] Call ParseLangArgs for all inputs
Needs ReviewPublic

Authored by hvdijk on Aug 27 2020, 4:09 AM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

clang/lib/CodeGen/BackendUtil.cpp contains multiple checks for attributes of LangOpts. The option processing that sets up LangOpts is mostly done by ParseLangArgs, which is skipped for LLVM IR files. Because of this, there are code generation differences when the -save-temps command line option is used: that command line option causes LLVM IR to be emitted to file and a new process to be spawned to process that file, which does not process options the same way.

An example of this is

typedef float __attribute__((ext_vector_type(2))) float2;
float2 foo (float2 a, float2 b, float2 c) {
  return a * b + c;
}

This used to generate different code with clang --target=mips -mcpu=mips32r5 -mfp64 -mmsa -O3 -ffp-contract=fast depending on whether -save-temps was also present, because the -ffp-contract=fast option affects instruction selection but was ignored for LLVM IR input files.

While CompilerInvocation::CreateFromArgs contained special exceptions for a few options that were handled by ParseLangArgs that also need to be handled for LLVM IR, there are many more, and just allowing ParseLangArgs to be called seems like the simpler fix.

For InputKind::Precompiled, -std=* options were previously silently ignored and continue to be silently ignored, as it is reasonable for users to add them and in fact this is done in quite a number of tests in the test suite.

For Language::LLVM_IR, -std=* options were previously silently ignored and now result in an error, as it is not reasonable for users to add them.

Diff Detail

Event Timeline

hvdijk created this revision.Aug 27 2020, 4:09 AM
hvdijk requested review of this revision.Aug 27 2020, 4:09 AM