SampleProfile: Check for missing debug locations
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 20 Mar 2015 00:56:55 +0000 (00:56 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 20 Mar 2015 00:56:55 +0000 (00:56 +0000)
Don't use `DebugLoc` accessors if we're pointing at null, which will be
a problem after a WIP patch to make the `DIDescriptor` accessors more
strict.  Caught by Frontend/profile-sample-use-loc-tracking.c (in
clang).

llvm-svn: 232792

llvm/lib/Transforms/Scalar/SampleProfile.cpp

index c7232a9..3e7cf04 100644 (file)
@@ -217,6 +217,9 @@ void SampleProfileLoader::printBlockWeight(raw_ostream &OS, BasicBlock *BB) {
 /// \returns The profiled weight of I.
 unsigned SampleProfileLoader::getInstWeight(Instruction &Inst) {
   DebugLoc DLoc = Inst.getDebugLoc();
+  if (DLoc.isUnknown())
+    return 0;
+
   unsigned Lineno = DLoc.getLine();
   if (Lineno < HeaderLineno)
     return 0;