|
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,47 @@ void Compilation::addDiagnostics(const Diagnostics& diagnostics) { |
1688 | 1689 | addDiag(diag); |
1689 | 1690 | } |
1690 | 1691 |
|
| 1692 | +bool shouldReportUninstantiatedDiag(const DiagCode& code) { |
| 1693 | + switch (code.getSubsystem()) { |
| 1694 | + case DiagSubsystem::Declarations: |
| 1695 | + return true; |
| 1696 | + case DiagSubsystem::Lookup: |
| 1697 | + switch (code.key()) { |
| 1698 | + case diag::ScopeIndexOutOfRange.key(): |
| 1699 | + case diag::InvalidScopeIndexExpression.key(): |
| 1700 | + case diag::CouldNotResolveHierarchicalPath.key(): |
| 1701 | + case diag::DotIntoInstArray.key(): |
| 1702 | + return false; |
| 1703 | + default: |
| 1704 | + break; |
| 1705 | + } |
| 1706 | + return true; |
| 1707 | + default: |
| 1708 | + break; |
| 1709 | + } |
| 1710 | + |
| 1711 | + return false; |
| 1712 | +} |
| 1713 | + |
1691 | 1714 | Diagnostic& Compilation::addDiag(Diagnostic diag) { |
1692 | 1715 | SLANG_ASSERT(!isFrozen()); |
1693 | 1716 |
|
1694 | | - if (diagsDisabled) { |
| 1717 | + auto suppressDiag = [&]() -> Diagnostic& { |
1695 | 1718 | tempDiag = std::move(diag); |
1696 | 1719 | return tempDiag; |
1697 | | - } |
1698 | | - |
1699 | | - auto isSuppressed = [](const Symbol* symbol) { |
1700 | | - while (symbol) { |
1701 | | - if (symbol->kind == SymbolKind::GenerateBlock) |
1702 | | - return symbol->as<GenerateBlockSymbol>().isUninstantiated; |
1703 | | - |
1704 | | - auto scope = symbol->getParentScope(); |
1705 | | - symbol = scope ? &scope->asSymbol() : nullptr; |
1706 | | - } |
1707 | | - return false; |
1708 | 1720 | }; |
1709 | 1721 |
|
| 1722 | + if (diagsDisabled) |
| 1723 | + return suppressDiag(); |
| 1724 | + |
1710 | 1725 | // Filter out diagnostics that came from inside an uninstantiated generate block. |
1711 | 1726 | SLANG_ASSERT(diag.symbol); |
1712 | 1727 | SLANG_ASSERT(diag.location); |
1713 | | - if (isSuppressed(diag.symbol)) { |
1714 | | - tempDiag = std::move(diag); |
1715 | | - return tempDiag; |
| 1728 | + |
| 1729 | + if (!diag.symbol->isInstantiated()) { |
| 1730 | + if (!hasFlag(CompilationFlags::CheckUninstantiated) || |
| 1731 | + !shouldReportUninstantiatedDiag(diag.code)) |
| 1732 | + return suppressDiag(); |
1716 | 1733 | } |
1717 | 1734 |
|
1718 | 1735 | const bool isError = diag.isError(); |
@@ -2449,7 +2466,8 @@ std::pair<Compilation::DefinitionLookupResult, bool> Compilation::resolveConfigR |
2449 | 2466 |
|
2450 | 2467 | Diagnostic* Compilation::errorMissingDef(std::string_view name, const Scope& scope, |
2451 | 2468 | SourceRange sourceRange, DiagCode code) const { |
2452 | | - if (hasFlag(CompilationFlags::IgnoreUnknownModules) || scope.isUninstantiated() || name.empty()) |
| 2469 | + if (hasFlag(CompilationFlags::IgnoreUnknownModules) || name.empty() || |
| 2470 | + (scope.isUninstantiated() && !hasFlag(CompilationFlags::CheckUninstantiated))) |
2453 | 2471 | return nullptr; |
2454 | 2472 |
|
2455 | 2473 | if (auto def = getExternDefinition(name, scope)) { |
|
0 commit comments