|
16 | 16 | #include "slang/ast/SystemSubroutine.h" |
17 | 17 | #include "slang/ast/types/TypePrinter.h" |
18 | 18 | #include "slang/diagnostics/DiagnosticEngine.h" |
| 19 | +#include "slang/diagnostics/Diagnostics.h" |
19 | 20 | #include "slang/diagnostics/LookupDiags.h" |
20 | 21 | #include "slang/parsing/Parser.h" |
21 | 22 | #include "slang/parsing/Preprocessor.h" |
@@ -1688,31 +1689,56 @@ void Compilation::addDiagnostics(const Diagnostics& diagnostics) { |
1688 | 1689 | addDiag(diag); |
1689 | 1690 | } |
1690 | 1691 |
|
| 1692 | +bool shouldReportUninstantiatedDiag(const DiagCode& code) { |
| 1693 | + static const flat_hash_set<DiagCode> BadLookupDiags = { |
| 1694 | + diag::ScopeIndexOutOfRange, |
| 1695 | + diag::InvalidScopeIndexExpression, |
| 1696 | + diag::CouldNotResolveHierarchicalPath, |
| 1697 | + diag::DotIntoInstArray, |
| 1698 | + }; |
| 1699 | + |
| 1700 | + switch (code.getSubsystem()) { |
| 1701 | + case DiagSubsystem::Declarations: |
| 1702 | + return true; |
| 1703 | + case DiagSubsystem::Lookup: |
| 1704 | + return !BadLookupDiags.contains(code); |
| 1705 | + default: |
| 1706 | + break; |
| 1707 | + } |
| 1708 | + |
| 1709 | + return false; |
| 1710 | +} |
| 1711 | + |
1691 | 1712 | Diagnostic& Compilation::addDiag(Diagnostic diag) { |
1692 | 1713 | SLANG_ASSERT(!isFrozen()); |
1693 | 1714 |
|
1694 | | - if (diagsDisabled) { |
| 1715 | + auto suppressDiag = [&]() -> Diagnostic& { |
1695 | 1716 | tempDiag = std::move(diag); |
1696 | 1717 | return tempDiag; |
1697 | | - } |
| 1718 | + }; |
1698 | 1719 |
|
1699 | | - auto isSuppressed = [](const Symbol* symbol) { |
| 1720 | + if (diagsDisabled) |
| 1721 | + return suppressDiag(); |
| 1722 | + |
| 1723 | + auto isInstantiated = [](const Symbol* symbol) { |
1700 | 1724 | while (symbol) { |
1701 | 1725 | if (symbol->kind == SymbolKind::GenerateBlock) |
1702 | | - return symbol->as<GenerateBlockSymbol>().isUninstantiated; |
| 1726 | + return !symbol->as<GenerateBlockSymbol>().isUninstantiated; |
1703 | 1727 |
|
1704 | 1728 | auto scope = symbol->getParentScope(); |
1705 | 1729 | symbol = scope ? &scope->asSymbol() : nullptr; |
1706 | 1730 | } |
1707 | | - return false; |
| 1731 | + return true; |
1708 | 1732 | }; |
1709 | 1733 |
|
1710 | 1734 | // Filter out diagnostics that came from inside an uninstantiated generate block. |
1711 | 1735 | SLANG_ASSERT(diag.symbol); |
1712 | 1736 | SLANG_ASSERT(diag.location); |
1713 | | - if (isSuppressed(diag.symbol)) { |
1714 | | - tempDiag = std::move(diag); |
1715 | | - return tempDiag; |
| 1737 | + |
| 1738 | + if (!isInstantiated(diag.symbol)) { |
| 1739 | + if (!hasFlag(CompilationFlags::CheckUninstantiated) || |
| 1740 | + !shouldReportUninstantiatedDiag(diag.code)) |
| 1741 | + return suppressDiag(); |
1716 | 1742 | } |
1717 | 1743 |
|
1718 | 1744 | const bool isError = diag.isError(); |
@@ -2449,7 +2475,8 @@ std::pair<Compilation::DefinitionLookupResult, bool> Compilation::resolveConfigR |
2449 | 2475 |
|
2450 | 2476 | Diagnostic* Compilation::errorMissingDef(std::string_view name, const Scope& scope, |
2451 | 2477 | SourceRange sourceRange, DiagCode code) const { |
2452 | | - if (hasFlag(CompilationFlags::IgnoreUnknownModules) || scope.isUninstantiated() || name.empty()) |
| 2478 | + if (hasFlag(CompilationFlags::IgnoreUnknownModules) || name.empty() || |
| 2479 | + (scope.isUninstantiated() && !hasFlag(CompilationFlags::CheckUninstantiated))) |
2453 | 2480 | return nullptr; |
2454 | 2481 |
|
2455 | 2482 | if (auto def = getExternDefinition(name, scope)) { |
|
0 commit comments