[MC] Change AsmParser to leverage Assembler during evaluation

Teach AsmParser to check with Assembler for when evaluating constant
expressions.  This improves the handing of preprocessor expressions
that must be resolved at parse time. This idiom can be found as
assembling-time assertion checks in source-level assemblers. Note that
this relies on the MCStreamer to keep sufficient tabs on Section /
Fragment information which the MCAsmStreamer does not. As a result the
textual output may fail where the equivalent object generation would
pass. This can most easily be resolved by folding the MCAsmStreamer
and MCObjectStreamer together which is planned for in a separate
patch.

Currently, this feature is only enabled for assembly input, keeping IR
compilation consistent between assembly and object generation.

Reviewers: echristo, rnk, probinson, espindola, peter.smith

Reviewed By: peter.smith

Subscribers: eraman, peter.smith, arichardson, jyknight, hiraditya, llvm-commits

Differential Revision: https://reviews.llvm.org/D45164

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@331218 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nirav Dave 2018-04-30 19:22:40 +00:00
parent 10efc31677
commit 12850bf731
2 changed files with 15 additions and 0 deletions

View File

@ -0,0 +1,12 @@
// REQUIRES: x86-registered-target
// RUN: %clang --target=x86_64-unknown-linux-gnu -c %s -o /dev/null
// Check that cc1as can use assembler info in object generation.
.data
foo:
.if . - foo == 0
.byte 0xaa
.else
.byte 0x00
.endif

View File

@ -435,6 +435,9 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
Str.get()->InitSections(Opts.NoExecStack);
}
// Assembly to object compilation should leverage assembly info.
Str->setUseAssemblerInfoForParsing(true);
bool Failed = false;
std::unique_ptr<MCAsmParser> Parser(