On 08/02/2015 01:35 PM, Justin Borodinsky wrote:
> I received a segfault during generation with the attached list-file.
> Attached is a patch to master which avoids the null pointer access
> causing it, but there may be a better fix.

Please try this patch instead.

Thanks,
-Brad
>From 33d52a96f7f622f96a3c656babe59795f7cabf8f Mon Sep 17 00:00:00 2001
Message-Id: <33d52a96f7f622f96a3c656babe59795f7cabf8f.1438633052.git.brad.k...@kitware.com>
From: Brad King <[email protected]>
Date: Mon, 3 Aug 2015 15:28:41 -0400
Subject: [PATCH] Reject TARGET_PDB_FILE for imported targets instead of
 crashing

Reported-by: Justin Borodinsky <[email protected]>
---
 Source/cmGeneratorExpressionNode.cxx                              | 7 +++++++
 Source/cmTarget.cxx                                               | 1 +
 .../GeneratorExpression/ImportedTarget-TARGET_PDB_FILE-result.txt | 1 +
 .../GeneratorExpression/ImportedTarget-TARGET_PDB_FILE-stderr.txt | 8 ++++++++
 .../GeneratorExpression/ImportedTarget-TARGET_PDB_FILE.cmake      | 2 ++
 Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake             | 1 +
 6 files changed, 20 insertions(+)
 create mode 100644 Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE-result.txt
 create mode 100644 Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE-stderr.txt
 create mode 100644 Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE.cmake

diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx
index f3527ff..140e2e4 100644
--- a/Source/cmGeneratorExpressionNode.cxx
+++ b/Source/cmGeneratorExpressionNode.cxx
@@ -1597,6 +1597,13 @@ struct TargetFilesystemArtifactResultCreator<ArtifactPdbTag>
                             cmGeneratorExpressionContext *context,
                             const GeneratorExpressionContent *content)
   {
+    if (target->IsImported())
+      {
+      ::reportError(context, content->GetOriginalExpression(),
+                    "TARGET_PDB_FILE not allowed for IMPORTED targets.");
+      return std::string();
+      }
+
     std::string language = target->Target->GetLinkerLanguage(context->Config);
 
     std::string pdbSupportVar = "CMAKE_" + language + "_LINKER_SUPPORTS_PDB";
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index cf33791..3b43e6f 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -3356,6 +3356,7 @@ void cmTarget::ComputeLinkClosure(const std::string& config,
   // Get languages built in this target.
   UNORDERED_SET<std::string> languages;
   LinkImplementation const* impl = this->GetLinkImplementation(config);
+  assert(impl);
   for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
       li != impl->Languages.end(); ++li)
     {
diff --git a/Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE-result.txt b/Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE-stderr.txt b/Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE-stderr.txt
new file mode 100644
index 0000000..d915ecb
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at ImportedTarget-TARGET_PDB_FILE.cmake:2 \(add_custom_target\):
+  Error evaluating generator expression:
+
+    \$<TARGET_PDB_FILE:empty>
+
+  TARGET_PDB_FILE not allowed for IMPORTED targets.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE.cmake b/Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE.cmake
new file mode 100644
index 0000000..c55c5d5
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE.cmake
@@ -0,0 +1,2 @@
+add_library(empty UNKNOWN IMPORTED)
+add_custom_target(custom COMMAND echo $<TARGET_PDB_FILE:empty>)
diff --git a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake
index 1c8fab5..cba3941 100644
--- a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake
+++ b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake
@@ -26,6 +26,7 @@ run_cmake(COMPILE_LANGUAGE-add_library)
 run_cmake(COMPILE_LANGUAGE-add_test)
 run_cmake(COMPILE_LANGUAGE-unknown-lang)
 
+run_cmake(ImportedTarget-TARGET_PDB_FILE)
 if(LINKER_SUPPORTS_PDB)
   run_cmake(NonValidTarget-TARGET_PDB_FILE)
   run_cmake(ValidTarget-TARGET_PDB_FILE)
-- 
2.4.6

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to