diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -54,6 +54,7 @@ CODEGENOPT(EnableAIXExtendedAltivecABI, 1, 0) ///< Set for -mabi=vec-extabi. Enables the extended Altivec ABI on AIX. ENUM_CODEGENOPT(FramePointer, FramePointerKind, 2, FramePointerKind::None) /// frame-pointer: all,non-leaf,none +CODEGENOPT(ClearASTBeforeCodeGen , 1, 1) ///< Free the AST before running code generation. Only works with -disable-free. CODEGENOPT(DisableFree , 1, 0) ///< Don't free memory. CODEGENOPT(DiscardValueNames , 1, 0) ///< Discard Value Names from the IR (LLVMContext flag) CODEGENOPT(DisableLLVMPasses , 1, 0) ///< Don't run any LLVM IR passes to get diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -120,6 +120,7 @@ bool IRGenFinished = false; bool TimerIsEnabled = false; + bool ASTCleared = false; std::unique_ptr Gen; @@ -329,6 +330,13 @@ if (LinkInModules()) return; + // FIXME: Fix cleanup issues with clearing the AST when we properly free + // things. + if (CodeGenOpts.DisableFree && CodeGenOpts.ClearASTBeforeCodeGen) { + Context->getAllocator().Reset(); + ASTCleared = true; + } + EmbedBitcode(getModule(), CodeGenOpts, llvm::MemoryBufferRef()); EmitBackendOutput(Diags, HeaderSearchOpts, CodeGenOpts, TargetOpts, @@ -568,6 +576,7 @@ // We do not know how to format other severities. return false; + // FIXME if (const Decl *ND = Gen->GetDeclForMangledName(D.getFunction().getName())) { // FIXME: Shouldn't need to truncate to uint32_t Diags.Report(ND->getASTContext().getFullLoc(ND->getLocation()), @@ -607,7 +616,7 @@ // function definition. We use the definition's right brace to differentiate // from diagnostics that genuinely relate to the function itself. FullSourceLoc Loc(DILoc, SourceMgr); - if (Loc.isInvalid()) + if (Loc.isInvalid() && !ASTCleared) if (const Decl *FD = Gen->GetDeclForMangledName(D.getFunction().getName())) Loc = FD->getASTContext().getFullLoc(FD->getLocation()); diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -182,6 +182,7 @@ llvm::Expected> Interpreter::create(std::unique_ptr CI) { llvm::Error Err = llvm::Error::success(); + CI->getCodeGenOpts().ClearASTBeforeCodeGen = false; auto Interp = std::unique_ptr(new Interpreter(std::move(CI), Err)); if (Err) diff --git a/clang/test/Frontend/optimization-remark-analysis.c b/clang/test/Frontend/optimization-remark-analysis.c --- a/clang/test/Frontend/optimization-remark-analysis.c +++ b/clang/test/Frontend/optimization-remark-analysis.c @@ -1,8 +1,8 @@ -// RUN: %clang -O1 -fvectorize -target x86_64-unknown-unknown -emit-llvm -Rpass-analysis -S %s -o - 2>&1 | FileCheck %s --check-prefix=RPASS -// RUN: %clang -O1 -fvectorize -target x86_64-unknown-unknown -emit-llvm -S %s -o - 2>&1 | FileCheck %s +// RUN: %clang -O1 -g2 -fvectorize -target x86_64-unknown-unknown -emit-llvm -Rpass-analysis -S %s -o - 2>&1 | FileCheck %s --check-prefix=RPASS +// RUN: %clang -O1 -g2 -fvectorize -target x86_64-unknown-unknown -emit-llvm -S %s -o - 2>&1 | FileCheck %s -// RPASS: {{.*}}:7:8: remark: loop not vectorized: loop contains a switch statement -// CHECK-NOT: {{.*}}:7:8: remark: loop not vectorized: loop contains a switch statement +// RPASS: {{.*}}:12:5: remark: loop not vectorized: loop contains a switch statement +// CHECK-NOT: {{.*}}:12:5: remark: loop not vectorized: loop contains a switch statement double foo(int N, int *Array) { double v = 0.0; diff --git a/clang/test/Misc/backend-stack-frame-diagnostics.cpp b/clang/test/Misc/backend-stack-frame-diagnostics.cpp --- a/clang/test/Misc/backend-stack-frame-diagnostics.cpp +++ b/clang/test/Misc/backend-stack-frame-diagnostics.cpp @@ -1,3 +1,5 @@ +// FIXME + // REQUIRES: x86-registered-target // RUN: %clang -target i386-apple-darwin -std=c++11 -fblocks -Wframe-larger-than=70 -Wno-stdlibcxx-not-found -Xclang -verify -o /dev/null -c %s // RUN: %clang -target i386-apple-darwin -std=c++11 -fblocks -Wframe-larger-than=70 -Wno-stdlibcxx-not-found -Xclang -verify -o /dev/null -c %s -DIS_SYSHEADER