[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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@288762 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Mandeep Singh Grang 2016-12-06 02:49:16 +00:00
parent 39afaeb8cc
commit e9895ed59a
4 changed files with 44 additions and 6 deletions

View File

@ -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">;
}

View File

@ -3116,6 +3116,24 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
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 {

View File

@ -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

View File

@ -426,10 +426,13 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
// 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) {