[PATCH] D27360: Fix D26214: Move error handling out of MC and to the callers.

Mandeep Singh Grang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 2 11:54:08 PST 2016


mgrang created this revision.
mgrang added reviewers: dgross, echristo, t.p.northover, rengolin, compnerd.
mgrang added subscribers: llvm-commits, cfe-commits.
mgrang added a project: clang-c.
Herald added a subscriber: mehdi_amini.

Related llvm patch: https://reviews.llvm.org/D27359


https://reviews.llvm.org/D27360

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  test/Driver/defsym.s
  tools/driver/cc1as_main.cpp


Index: tools/driver/cc1as_main.cpp
===================================================================
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -426,10 +426,23 @@
 
   // Set values for symbols, if any.
   for (auto &S : Opts.SymbolDefs) {
-    if (Ctx.setSymbolValue(Parser->getStreamer(), S)) {
+    auto Pair = StringRef(S).split('=');
+    auto Sym = Pair.first;
+    auto Val = Pair.second;
+
+    if (Sym.empty() || Val.empty()) {
+      Diags.Report(diag::err_drv_defsym_invalid_format) << S;
       Failed = true;
       break;
     }
+    int64_t Value;
+    if (Val.getAsInteger(0, Value)) {
+      Diags.Report(diag::err_drv_defsym_invalid_symval) << Val;
+      Failed = true;
+      break;
+    }
+
+    Ctx.setSymbolValue(Parser->getStreamer(), Sym, Value);
   }
 
   if (!Failed) {
Index: test/Driver/defsym.s
===================================================================
--- test/Driver/defsym.s
+++ test/Driver/defsym.s
@@ -17,6 +17,11 @@
 // CHECK-DEFSYM-ERR1: error: defsym must be of the form: sym=value: abc=
 
 // RUN: not %clang -c -integrated-as -o /dev/null %s \
-// RUN: -Wa,-defsym,abc=1a2b3c \
+// RUN: -Wa,-defsym,=123 \
 // RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-DEFSYM-ERR2
-// CHECK-DEFSYM-ERR2: error: Value is not an integer: 1a2b3c
+// CHECK-DEFSYM-ERR2: error: defsym must be of the form: sym=value: =123
+
+// RUN: not %clang -c -integrated-as -o /dev/null %s \
+// RUN: -Wa,-defsym,abc=1a2b3c \
+// RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-DEFSYM-ERR3
+// CHECK-DEFSYM-ERR3: error: Value is not an integer: 1a2b3c
Index: include/clang/Basic/DiagnosticDriverKinds.td
===================================================================
--- include/clang/Basic/DiagnosticDriverKinds.td
+++ include/clang/Basic/DiagnosticDriverKinds.td
@@ -277,4 +277,6 @@
   InGroup<InvalidOrNonExistentDirectory>;
 
 def err_drv_unsupported_linker : Error<"unsupported value '%0' for -linker option">;
+def err_drv_defsym_invalid_format : Error<"defsym must be of the form: sym=value: %0">;
+def err_drv_defsym_invalid_symval : Error<"Value is not an integer: %0">;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27360.80115.patch
Type: text/x-patch
Size: 2132 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161202/6cb403de/attachment.bin>


More information about the cfe-commits mailing list