Add check to make sure file exists before running preprocessor.
(If the file doesn't exist, clang ends up crashing, so we'd like to avoid that.)
This commit is contained in:
11
module.cpp
11
module.cpp
@@ -152,6 +152,17 @@ Module::CompileFile() {
|
|||||||
bool runPreprocessor = g->runCPP;
|
bool runPreprocessor = g->runCPP;
|
||||||
|
|
||||||
if (runPreprocessor) {
|
if (runPreprocessor) {
|
||||||
|
if (filename != NULL) {
|
||||||
|
// Try to open the file first, since otherwise we crash in the
|
||||||
|
// preprocessor if the file doesn't exist.
|
||||||
|
FILE *f = fopen(filename, "r");
|
||||||
|
if (!f) {
|
||||||
|
perror(filename);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
llvm::raw_string_ostream os(buffer);
|
llvm::raw_string_ostream os(buffer);
|
||||||
execPreprocessor((filename != NULL) ? filename : "-", &os);
|
execPreprocessor((filename != NULL) ? filename : "-", &os);
|
||||||
|
|||||||
Reference in New Issue
Block a user