@@ -281,6 +281,9 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
281281 // / Whether the current function has a DISubprogram attached to it.
282282 bool HasDebugInfo = false ;
283283
284+ // / Whether source was present on the first DIFile encountered in each CU.
285+ DenseMap<const DICompileUnit *, bool > HasSourceDebugInfo;
286+
284287 // / Stores the count of how many objects were passed to llvm.localescape for a
285288 // / given function and the largest index passed to llvm.localrecover.
286289 DenseMap<Function *, std::pair<unsigned , unsigned >> FrameEscapeInfo;
@@ -519,6 +522,9 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
519522 // / Module-level verification that all @llvm.experimental.deoptimize
520523 // / declarations share the same calling convention.
521524 void verifyDeoptimizeCallingConvs ();
525+
526+ // / Verify all-or-nothing property of DIFile source attribute within a CU.
527+ void verifySourceDebugInfo (const DICompileUnit &U, const DIFile &F);
522528};
523529
524530} // end anonymous namespace
@@ -1032,6 +1038,8 @@ void Verifier::visitDICompileUnit(const DICompileUnit &N) {
10321038 AssertDI (!N.getFile ()->getFilename ().empty (), " invalid filename" , &N,
10331039 N.getFile ());
10341040
1041+ verifySourceDebugInfo (N, *N.getFile ());
1042+
10351043 AssertDI ((N.getEmissionKind () <= DICompileUnit::LastEmissionKind),
10361044 " invalid emission kind" , &N);
10371045
@@ -1109,6 +1117,8 @@ void Verifier::visitDISubprogram(const DISubprogram &N) {
11091117 AssertDI (N.isDistinct (), " subprogram definitions must be distinct" , &N);
11101118 AssertDI (Unit, " subprogram definitions must have a compile unit" , &N);
11111119 AssertDI (isa<DICompileUnit>(Unit), " invalid unit type" , &N, Unit);
1120+ if (N.getFile ())
1121+ verifySourceDebugInfo (*N.getUnit (), *N.getFile ());
11121122 } else {
11131123 // Subprogram declarations (part of the type hierarchy).
11141124 AssertDI (!Unit, " subprogram declarations must not have a compile unit" , &N);
@@ -4744,6 +4754,14 @@ void Verifier::verifyDeoptimizeCallingConvs() {
47444754 }
47454755}
47464756
4757+ void Verifier::verifySourceDebugInfo (const DICompileUnit &U, const DIFile &F) {
4758+ bool HasSource = F.getSource ().hasValue ();
4759+ if (!HasSourceDebugInfo.count (&U))
4760+ HasSourceDebugInfo[&U] = HasSource;
4761+ AssertDI (HasSource == HasSourceDebugInfo[&U],
4762+ " inconsistent use of embedded source" );
4763+ }
4764+
47474765// ===----------------------------------------------------------------------===//
47484766// Implement the public interfaces to this file...
47494767// ===----------------------------------------------------------------------===//
0 commit comments