From 12850bf731681a2c32ee5d06ad2b8c411f7e2162 Mon Sep 17 00:00:00 2001 From: Nirav Dave Date: Mon, 30 Apr 2018 19:22:40 +0000 Subject: [PATCH] [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 --- test/CodeGen/asm-parser-info.S | 12 ++++++++++++ tools/driver/cc1as_main.cpp | 3 +++ 2 files changed, 15 insertions(+) create mode 100644 test/CodeGen/asm-parser-info.S diff --git a/test/CodeGen/asm-parser-info.S b/test/CodeGen/asm-parser-info.S new file mode 100644 index 0000000000..62145c0a74 --- /dev/null +++ b/test/CodeGen/asm-parser-info.S @@ -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 diff --git a/tools/driver/cc1as_main.cpp b/tools/driver/cc1as_main.cpp index 1c6cc36e68..05a4d9cf06 100644 --- a/tools/driver/cc1as_main.cpp +++ b/tools/driver/cc1as_main.cpp @@ -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 Parser( -- 2.40.0