From 4d733af3c7a6c51eb848cbeb0076458658ec2e8a Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Wed, 6 Jul 2011 11:33:33 +0100 Subject: [PATCH] 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.) --- module.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/module.cpp b/module.cpp index b5927ab8..09db04fd 100644 --- a/module.cpp +++ b/module.cpp @@ -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);