Skip to content

Commit 52624d7

Browse files
authored
[clang] Check '-Wp,' arg has values before accesing (#113677)
Executing `clang -Wp,` without any argument value causes Undefined Behavior due to accessing a SmallVector without elements Executing clang in debug mode raises an assert and Valgrind complains as follow: ``` $ valgrind bin/clang -Wp, ==18620== Memcheck, a memory error detector ==18620== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al. ==18620== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info ==18620== Command: bin/clang -Wp, ==18620== ==18620== Conditional jump or move depends on uninitialised value(s) ==18620== at 0x44F215B: clang::driver::Driver::TranslateInputArgs(llvm::opt::InputArgList const&) const (in /home/jaime/devel/llvm-project/build/bin/clang-20) ==18620== by 0x4515831: clang::driver::Driver::BuildCompilation(llvm::ArrayRef<char const*>) (in /home/jaime/devel/llvm-project/build/bin/clang-20) ==18620== by 0x10B3435: clang_main(int, char**, llvm::ToolContext const&) (in /home/jaime/devel/llvm-project/build/bin/clang-20) ==18620== by 0xF78F99: main (in /home/jaime/devel/llvm-project/build/bin/clang-20) ==18620== ... ```
1 parent 29d4d7f commit 52624d7

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
454454
// some build systems. We don't try to be complete here because we don't
455455
// care to encourage this usage model.
456456
if (A->getOption().matches(options::OPT_Wp_COMMA) &&
457+
A->getNumValues() > 0 &&
457458
(A->getValue(0) == StringRef("-MD") ||
458459
A->getValue(0) == StringRef("-MMD"))) {
459460
// Rewrite to -MD/-MMD along with -MF.

0 commit comments

Comments
 (0)