]> granicus.if.org Git - clang/commitdiff
[MC] Change AsmParser to leverage Assembler during evaluation
authorNirav Dave <niravd@google.com>
Mon, 30 Apr 2018 19:22:40 +0000 (19:22 +0000)
committerNirav Dave <niravd@google.com>
Mon, 30 Apr 2018 19:22:40 +0000 (19:22 +0000)
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 [new file with mode: 0644]
tools/driver/cc1as_main.cpp

diff --git a/test/CodeGen/asm-parser-info.S b/test/CodeGen/asm-parser-info.S
new file mode 100644 (file)
index 0000000..62145c0
--- /dev/null
@@ -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
index 1c6cc36e6800aed714e890703193f451294d2bc5..05a4d9cf0627f8573d2fbaca85eb5266fdad587c 100644 (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(