diff --git a/lib/IR/DebugInfoMetadata.cpp b/lib/IR/DebugInfoMetadata.cpp
index 21a95f9f9fc..467d21ad36a 100644
--- a/lib/IR/DebugInfoMetadata.cpp
+++ b/lib/IR/DebugInfoMetadata.cpp
@@ -77,9 +77,11 @@ static StringRef getString(const MDString *S) {
   return StringRef();
 }
 
+#ifndef NDEBUG
 static bool isCanonical(const MDString *S) {
   return !S || !S->getString().empty();
 }
+#endif
 
 GenericDebugNode *GenericDebugNode::getImpl(LLVMContext &Context, unsigned Tag,
                                             MDString *Header,