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:
Matt Pharr
2011-07-06 11:33:33 +01:00
parent b8dae5cb9a
commit 4d733af3c7

View File

@@ -152,6 +152,17 @@ Module::CompileFile() {
bool runPreprocessor = g->runCPP;
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;
llvm::raw_string_ostream os(buffer);
execPreprocessor((filename != NULL) ? filename : "-", &os);