sammccall created this revision. sammccall added a reviewer: kadircet. Herald added a project: clang. Herald added a subscriber: cfe-commits.
These files tend to be hand-authored, and people get very confused. I can't think of any reason that such whitespace would be intended. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D80160 Files: clang/lib/Tooling/CompilationDatabase.cpp clang/test/Tooling/fixed-database.cpp Index: clang/test/Tooling/fixed-database.cpp =================================================================== --- clang/test/Tooling/fixed-database.cpp +++ clang/test/Tooling/fixed-database.cpp @@ -3,9 +3,10 @@ // RUN: cp "%s" "%t/Src/test.cpp" // RUN: mkdir -p %t/Include // RUN: cp "%S/Inputs/fixed-header.h" "%t/Include/" +// RUN: echo '# this is a comment' >> %t/compile_flags.txt // -I flag is relative to %t (where compile_flags is), not Src/. // RUN: echo '-IInclude/' >> %t/compile_flags.txt -// RUN: echo "-Dklazz=class" >> %t/compile_flags.txt +// RUN: echo " -Dklazz=class " >> %t/compile_flags.txt // RUN: echo '-std=c++11' >> %t/compile_flags.txt // RUN: clang-check "%t/Src/test.cpp" 2>&1 // RUN: echo > %t/compile_flags.txt Index: clang/lib/Tooling/CompilationDatabase.cpp =================================================================== --- clang/lib/Tooling/CompilationDatabase.cpp +++ clang/lib/Tooling/CompilationDatabase.cpp @@ -368,8 +368,14 @@ ErrorMsg = "Error while opening fixed database: " + Result.message(); return nullptr; } - std::vector<std::string> Args{llvm::line_iterator(**File), - llvm::line_iterator()}; + std::vector<std::string> Args; + for (llvm::StringRef Line : + llvm::make_range(llvm::line_iterator(**File), llvm::line_iterator())) { + // Stray whitespace is almost certainly unintended. + Line = Line.trim(); + if (!Line.empty()) + Args.push_back(Line.str()); + } return std::make_unique<FixedCompilationDatabase>( llvm::sys::path::parent_path(Path), std::move(Args)); }
Index: clang/test/Tooling/fixed-database.cpp =================================================================== --- clang/test/Tooling/fixed-database.cpp +++ clang/test/Tooling/fixed-database.cpp @@ -3,9 +3,10 @@ // RUN: cp "%s" "%t/Src/test.cpp" // RUN: mkdir -p %t/Include // RUN: cp "%S/Inputs/fixed-header.h" "%t/Include/" +// RUN: echo '# this is a comment' >> %t/compile_flags.txt // -I flag is relative to %t (where compile_flags is), not Src/. // RUN: echo '-IInclude/' >> %t/compile_flags.txt -// RUN: echo "-Dklazz=class" >> %t/compile_flags.txt +// RUN: echo " -Dklazz=class " >> %t/compile_flags.txt // RUN: echo '-std=c++11' >> %t/compile_flags.txt // RUN: clang-check "%t/Src/test.cpp" 2>&1 // RUN: echo > %t/compile_flags.txt Index: clang/lib/Tooling/CompilationDatabase.cpp =================================================================== --- clang/lib/Tooling/CompilationDatabase.cpp +++ clang/lib/Tooling/CompilationDatabase.cpp @@ -368,8 +368,14 @@ ErrorMsg = "Error while opening fixed database: " + Result.message(); return nullptr; } - std::vector<std::string> Args{llvm::line_iterator(**File), - llvm::line_iterator()}; + std::vector<std::string> Args; + for (llvm::StringRef Line : + llvm::make_range(llvm::line_iterator(**File), llvm::line_iterator())) { + // Stray whitespace is almost certainly unintended. + Line = Line.trim(); + if (!Line.empty()) + Args.push_back(Line.str()); + } return std::make_unique<FixedCompilationDatabase>( llvm::sys::path::parent_path(Path), std::move(Args)); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits