From 926ea9574ef8adc7d81db6b57b0ad83707b90fcd Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 18 Sep 2015 15:41:48 -0400 Subject: RunClang: Exit with error if compiler invocation argument parsing fails If an error occurs during CompilerInvocation::CreateFromArgs then exit with an error code immediately. --- src/RunClang.cxx | 3 +++ test/CMakeLists.txt | 2 ++ test/expect/cmd.std-c++98-src-c.result.txt | 1 + test/expect/cmd.std-c++98-src-c.stderr.txt | 1 + test/expect/cmd.std-c89-src-cxx.result.txt | 1 + test/expect/cmd.std-c89-src-cxx.stderr.txt | 1 + 6 files changed, 9 insertions(+) create mode 100644 test/expect/cmd.std-c++98-src-c.result.txt create mode 100644 test/expect/cmd.std-c++98-src-c.stderr.txt create mode 100644 test/expect/cmd.std-c89-src-cxx.result.txt create mode 100644 test/expect/cmd.std-c89-src-cxx.stderr.txt diff --git a/src/RunClang.cxx b/src/RunClang.cxx index fe77fbc..bb88c1a 100644 --- a/src/RunClang.cxx +++ b/src/RunClang.cxx @@ -344,6 +344,9 @@ static int runClangImpl(const char* const* argBeg, const char* const* cmdArgEnd = cmdArgBeg + cmd->getArguments().size(); if (clang::CompilerInvocation::CreateFromArgs (CI->getInvocation(), cmdArgBeg, cmdArgEnd, *diags)) { + if (diags->hasErrorOccurred()) { + return 1; + } result = runClangCI(CI.get(), opts) && result; } else { result = false; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0e416e6..29fcecf 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -136,6 +136,8 @@ castxml_test_cmd(gccxml-and-objc2 --castxml-gccxml ${empty_mm}) castxml_test_cmd(gccxml-empty-c++98 --castxml-gccxml -std=c++98 ${empty_cxx}) castxml_test_cmd(gccxml-empty-c++98-E --castxml-gccxml -std=c++98 ${empty_cxx} -E) castxml_test_cmd(gccxml-empty-c++98-c --castxml-gccxml -std=c++98 ${empty_cxx} -c) +castxml_test_cmd(std-c++98-src-c -std=c++98 ${empty_c}) +castxml_test_cmd(std-c89-src-cxx -std=c89 ${empty_cxx}) castxml_test_cmd(input-missing ${input}/does-not-exist.c) castxml_test_cmd(o-missing -o) castxml_test_cmd(start-missing --castxml-start) diff --git a/test/expect/cmd.std-c++98-src-c.result.txt b/test/expect/cmd.std-c++98-src-c.result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/test/expect/cmd.std-c++98-src-c.result.txt @@ -0,0 +1 @@ +1 diff --git a/test/expect/cmd.std-c++98-src-c.stderr.txt b/test/expect/cmd.std-c++98-src-c.stderr.txt new file mode 100644 index 0000000..c2537f9 --- /dev/null +++ b/test/expect/cmd.std-c++98-src-c.stderr.txt @@ -0,0 +1 @@ +^error: invalid argument '-std=c\+\+98' not allowed with 'C/ObjC'$ diff --git a/test/expect/cmd.std-c89-src-cxx.result.txt b/test/expect/cmd.std-c89-src-cxx.result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/test/expect/cmd.std-c89-src-cxx.result.txt @@ -0,0 +1 @@ +1 diff --git a/test/expect/cmd.std-c89-src-cxx.stderr.txt b/test/expect/cmd.std-c89-src-cxx.stderr.txt new file mode 100644 index 0000000..b05c32e --- /dev/null +++ b/test/expect/cmd.std-c89-src-cxx.stderr.txt @@ -0,0 +1 @@ +^error: invalid argument '-std=c89' not allowed with 'C\+\+/ObjC\+\+'$ -- cgit v0.12