r236898 - Fix BackendConsumer::EmitOptimizationMessage()
Diego Novillo
dnovillo at google.com
Fri May 8 13:59:56 PDT 2015
Author: dnovillo
Date: Fri May 8 15:59:56 2015
New Revision: 236898
URL: http://llvm.org/viewvc/llvm-project?rev=236898&view=rev
Log:
Fix BackendConsumer::EmitOptimizationMessage()
Patch from Geoff Berry <gberry at codeaurora.org>
Fix BackendConsumer::EmitOptimizationMessage() to check if the
DiagnosticInfoOptimizationBase object has a valid location before
calling getLocation() to avoid dereferencing a null pointer inside
getLocation() when no debug info is present.
Added:
cfe/trunk/test/Misc/backend-optimization-failure-nodbg.cpp
Modified:
cfe/trunk/lib/CodeGen/CodeGenAction.cpp
Modified: cfe/trunk/lib/CodeGen/CodeGenAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenAction.cpp?rev=236898&r1=236897&r2=236898&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenAction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp Fri May 8 15:59:56 2015
@@ -434,13 +434,16 @@ void BackendConsumer::EmitOptimizationMe
FileManager &FileMgr = SourceMgr.getFileManager();
StringRef Filename;
unsigned Line, Column;
- D.getLocation(&Filename, &Line, &Column);
SourceLocation DILoc;
- const FileEntry *FE = FileMgr.getFile(Filename);
- if (FE && Line > 0) {
- // If -gcolumn-info was not used, Column will be 0. This upsets the
- // source manager, so pass 1 if Column is not set.
- DILoc = SourceMgr.translateFileLineCol(FE, Line, Column ? Column : 1);
+
+ if (D.isLocationAvailable()) {
+ D.getLocation(&Filename, &Line, &Column);
+ const FileEntry *FE = FileMgr.getFile(Filename);
+ if (FE && Line > 0) {
+ // If -gcolumn-info was not used, Column will be 0. This upsets the
+ // source manager, so pass 1 if Column is not set.
+ DILoc = SourceMgr.translateFileLineCol(FE, Line, Column ? Column : 1);
+ }
}
// If a location isn't available, try to approximate it using the associated
@@ -455,7 +458,7 @@ void BackendConsumer::EmitOptimizationMe
<< AddFlagValue(D.getPassName() ? D.getPassName() : "")
<< D.getMsg().str();
- if (DILoc.isInvalid())
+ if (DILoc.isInvalid() && D.isLocationAvailable())
// If we were not able to translate the file:line:col information
// back to a SourceLocation, at least emit a note stating that
// we could not translate this location. This can happen in the
Added: cfe/trunk/test/Misc/backend-optimization-failure-nodbg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/backend-optimization-failure-nodbg.cpp?rev=236898&view=auto
==============================================================================
--- cfe/trunk/test/Misc/backend-optimization-failure-nodbg.cpp (added)
+++ cfe/trunk/test/Misc/backend-optimization-failure-nodbg.cpp Fri May 8 15:59:56 2015
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -O3 -emit-llvm -S -verify -o /dev/null
+// REQUIRES: x86-registered-target
+
+// Test verifies optimization failures generated by the backend are handled
+// correctly by clang. LLVM tests verify all of the failure conditions.
+
+void test_switch(int *A, int *B, int Length) {
+#pragma clang loop vectorize(enable) unroll(disable)
+ for (int i = 0; i < Length; i++) {
+ switch (A[i]) {
+ case 0:
+ B[i] = 1;
+ break;
+ case 1:
+ B[i] = 2;
+ break;
+ default:
+ B[i] = 3;
+ }
+ }
+/* expected-warning {{loop not vectorized: failed explicitly specified loop vectorization}} */ }
More information about the cfe-commits
mailing list