r288762 - [clang] Fix D26214: Move error handling out of MC and to the callers.

Mandeep Singh Grang via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 5 18:49:16 PST 2016


Author: mgrang
Date: Mon Dec  5 20:49:16 2016
New Revision: 288762

URL: http://llvm.org/viewvc/llvm-project?rev=288762&view=rev
Log:
[clang] Fix D26214: Move error handling out of MC and to the callers.

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

Reviewers: echristo, t.p.northover, rengolin, grosbach, compnerd

Subscribers: mehdi_amini, cfe-commits, llvm-commits

Tags: #clang-c

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

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
    cfe/trunk/lib/Driver/Tools.cpp
    cfe/trunk/test/Driver/defsym.s
    cfe/trunk/tools/driver/cc1as_main.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=288762&r1=288761&r2=288762&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Mon Dec  5 20:49:16 2016
@@ -277,4 +277,6 @@ def warn_drv_ps4_sdk_dir : Warning<
   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">;
 }

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=288762&r1=288761&r2=288762&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Mon Dec  5 20:49:16 2016
@@ -3116,6 +3116,24 @@ static void CollectArgsForIntegratedAsse
                  Value.startswith("-mhwdiv") || Value.startswith("-march")) {
         // Do nothing, we'll validate it later.
       } else if (Value == "-defsym") {
+          if (A->getNumValues() != 2) {
+            D.Diag(diag::err_drv_defsym_invalid_format) << Value;
+            break;
+          }
+          const char *S = A->getValue(1);
+          auto Pair = StringRef(S).split('=');
+          auto Sym = Pair.first;
+          auto SVal = Pair.second;
+
+          if (Sym.empty() || SVal.empty()) {
+            D.Diag(diag::err_drv_defsym_invalid_format) << S;
+            break;
+          }
+          int64_t IVal;
+          if (SVal.getAsInteger(0, IVal)) {
+            D.Diag(diag::err_drv_defsym_invalid_symval) << SVal;
+            break;
+          }
           CmdArgs.push_back(Value.data());
           TakeNextArg = true;
       } else {

Modified: cfe/trunk/test/Driver/defsym.s
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/defsym.s?rev=288762&r1=288761&r2=288762&view=diff
==============================================================================
--- cfe/trunk/test/Driver/defsym.s (original)
+++ cfe/trunk/test/Driver/defsym.s Mon Dec  5 20:49:16 2016
@@ -17,6 +17,21 @@
 // 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
+
+// RUN: not %clang -c -integrated-as -o /dev/null %s \
+// RUN: -Wa,-defsym \
+// RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-DEFSYM-ERR4
+
+// RUN: not %clang -c -integrated-as -o /dev/null %s \
+// RUN: -Wa,-defsym, \
+// RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-DEFSYM-ERR4
+
+// CHECK-DEFSYM-ERR4: error: defsym must be of the form: sym=value: -defsym

Modified: cfe/trunk/tools/driver/cc1as_main.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1as_main.cpp?rev=288762&r1=288761&r2=288762&view=diff
==============================================================================
--- cfe/trunk/tools/driver/cc1as_main.cpp (original)
+++ cfe/trunk/tools/driver/cc1as_main.cpp Mon Dec  5 20:49:16 2016
@@ -426,10 +426,13 @@ static bool ExecuteAssembler(AssemblerIn
 
   // Set values for symbols, if any.
   for (auto &S : Opts.SymbolDefs) {
-    if (Ctx.setSymbolValue(Parser->getStreamer(), S)) {
-      Failed = true;
-      break;
-    }
+    auto Pair = StringRef(S).split('=');
+    auto Sym = Pair.first;
+    auto Val = Pair.second;
+    int64_t Value;
+    // We have already error checked this in the driver.
+    Val.getAsInteger(0, Value);
+    Ctx.setSymbolValue(Parser->getStreamer(), Sym, Value);
   }
 
   if (!Failed) {




More information about the cfe-commits mailing list