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.
http://reviews.llvm.org/D9449
Files:
lib/CodeGen/CodeGenAction.cpp
test/Misc/backend-optimization-failure-nodbg.cpp
Index: lib/CodeGen/CodeGenAction.cpp
===================================================================
--- lib/CodeGen/CodeGenAction.cpp
+++ lib/CodeGen/CodeGenAction.cpp
@@ -434,7 +434,13 @@
FileManager &FileMgr = SourceMgr.getFileManager();
StringRef Filename;
unsigned Line, Column;
- D.getLocation(&Filename, &Line, &Column);
+ if (D.isLocationAvailable())
+ D.getLocation(&Filename, &Line, &Column);
+ else {
+ Filename = "<unknown>";
+ Line = 0;
+ Column = 0;
+ }
SourceLocation DILoc;
const FileEntry *FE = FileMgr.getFile(Filename);
if (FE && Line > 0) {
Index: test/Misc/backend-optimization-failure-nodbg.cpp
===================================================================
--- /dev/null
+++ test/Misc/backend-optimization-failure-nodbg.cpp
@@ -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-note {{could not determine the original source location for
<unknown>:0:0}} expected-warning {{loop not vectorized: failed explicitly
specified loop vectorization}} */ }
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
Index: lib/CodeGen/CodeGenAction.cpp
===================================================================
--- lib/CodeGen/CodeGenAction.cpp
+++ lib/CodeGen/CodeGenAction.cpp
@@ -434,7 +434,13 @@
FileManager &FileMgr = SourceMgr.getFileManager();
StringRef Filename;
unsigned Line, Column;
- D.getLocation(&Filename, &Line, &Column);
+ if (D.isLocationAvailable())
+ D.getLocation(&Filename, &Line, &Column);
+ else {
+ Filename = "<unknown>";
+ Line = 0;
+ Column = 0;
+ }
SourceLocation DILoc;
const FileEntry *FE = FileMgr.getFile(Filename);
if (FE && Line > 0) {
Index: test/Misc/backend-optimization-failure-nodbg.cpp
===================================================================
--- /dev/null
+++ test/Misc/backend-optimization-failure-nodbg.cpp
@@ -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-note {{could not determine the original source location for <unknown>:0:0}} expected-warning {{loop not vectorized: failed explicitly specified loop vectorization}} */ }
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits