Skip to content

Commit

Permalink
CompilerStack: Use location of the current contract as default locati…
Browse files Browse the repository at this point in the history
…on in post-analysis errors
  • Loading branch information
cameel committed Dec 17, 2024
1 parent 6c28421 commit 2ccf0df
Show file tree
Hide file tree
Showing 27 changed files with 77 additions and 31 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Language Features:


Compiler Features:
* Error Reporting: Errors reported during code generation now point at the location of the contract when more fine-grained location is not available.
* SMTChecker: Z3 is now a runtime dependency, not a build dependency (except for emscripten build).


Expand Down
43 changes: 36 additions & 7 deletions libsolidity/interface/CompilerStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,11 +779,11 @@ bool CompilerStack::compile(State _stopAfter)
}
catch (Error const& _error)
{
m_errorReporter.codeGenerationError(_error);
reportCodeGenerationError(_error, contract);
}
catch (UnimplementedFeatureError const& _error)
{
reportUnimplementedFeatureError(_error);
reportUnimplementedFeatureError(_error, contract);
}

if (m_errorReporter.hasErrors())
Expand Down Expand Up @@ -1614,7 +1614,7 @@ void CompilerStack::generateEVMFromIR(ContractDefinition const& _contract)
if (stack.hasErrors())
{
for (std::shared_ptr<Error const> const& error: stack.errors())
reportIRPostAnalysisError(error.get());
reportIRPostAnalysisError(error.get(), compiledContract.contract);
return;
}

Expand Down Expand Up @@ -2010,18 +2010,47 @@ experimental::Analysis const& CompilerStack::experimentalAnalysis() const
return *m_experimentalAnalysis;
}

void CompilerStack::reportUnimplementedFeatureError(UnimplementedFeatureError const& _error)
void CompilerStack::reportUnimplementedFeatureError(
UnimplementedFeatureError const& _error,
ContractDefinition const* _contractDefinition
)
{
solAssert(_error.comment(), "Errors must include a message for the user.");
if (_error.sourceLocation().sourceName)
solAssert(m_sources.count(*_error.sourceLocation().sourceName) != 0);

m_errorReporter.unimplementedFeatureError(
1834_error,
(_error.sourceLocation().sourceName || !_contractDefinition) ?
_error.sourceLocation() :
_contractDefinition->location(),
*_error.comment()
);
}

m_errorReporter.unimplementedFeatureError(1834_error, _error.sourceLocation(), *_error.comment());
void CompilerStack::reportCodeGenerationError(Error const& _error, ContractDefinition const* _contractDefinition)
{
solAssert(_error.type() == Error::Type::CodeGenerationError);
solAssert(_error.comment(), "Errors must include a message for the user.");
if (_error.sourceLocation() && _error.sourceLocation()->sourceName)
solAssert(m_sources.count(*_error.sourceLocation()->sourceName) != 0);
solAssert(_contractDefinition);

m_errorReporter.codeGenerationError(
_error.errorId(),
(_error.sourceLocation() && _error.sourceLocation()->sourceName) ?
*_error.sourceLocation() :
_contractDefinition->location(),
*_error.comment()
);
}

void CompilerStack::reportIRPostAnalysisError(Error const* _error)
void CompilerStack::reportIRPostAnalysisError(Error const* _error, ContractDefinition const* _contractDefinition)
{
solAssert(_error);
solAssert(_error->comment(), "Errors must include a message for the user.");
solAssert(!_error->secondarySourceLocation());
solAssert(_contractDefinition);

// Do not report Yul warnings and infos. These are only reported in pure Yul compilation.
if (!Error::isError(_error->severity()))
Expand All @@ -2032,7 +2061,7 @@ void CompilerStack::reportIRPostAnalysisError(Error const* _error)
_error->type(),
// Ignore the original location. It's likely missing, but even if not, it points at Yul source.
// CompilerStack can only point at locations in Solidity sources.
SourceLocation{},
_contractDefinition->location(),
*_error->comment()
);
}
8 changes: 6 additions & 2 deletions libsolidity/interface/CompilerStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,12 @@ class CompilerStack: public langutil::CharStreamProvider, public evmasm::Abstrac
FunctionDefinition const& _function
) const;

void reportUnimplementedFeatureError(langutil::UnimplementedFeatureError const& _error);
void reportIRPostAnalysisError(langutil::Error const* _error);
void reportUnimplementedFeatureError(
langutil::UnimplementedFeatureError const& _error,
ContractDefinition const* _contractDefinition = nullptr
);
void reportCodeGenerationError(langutil::Error const& _error, ContractDefinition const* _contractDefinition);
void reportIRPostAnalysisError(langutil::Error const* _error, ContractDefinition const* _contractDefinition);

ReadCallback::Callback m_readFile;
OptimiserSettings m_optimiserSettings;
Expand Down
3 changes: 3 additions & 0 deletions libyul/YulStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ Dialect const& YulStack::dialect() const

void YulStack::reportUnimplementedFeatureError(UnimplementedFeatureError const& _error)
{
yulAssert(m_charStream);
yulAssert(_error.comment(), "Errors must include a message for the user.");
if (_error.sourceLocation().sourceName)
yulAssert(*_error.sourceLocation().sourceName == m_charStream->name());
m_errorReporter.unimplementedFeatureError(1920_error, _error.sourceLocation(), *_error.comment());
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,19 @@
"component": "general",
"errorCode": "1284",
"formattedMessage": "CodeGenerationError: Some immutables were read from but never assigned, possibly because of optimization.
--> C:4:1:
|
4 | contract C {
| ^ (Relevant source part starts here and spans across multiple lines).

",
"message": "Some immutables were read from but never assigned, possibly because of optimization.",
"severity": "error",
"sourceLocation": {
"end": 320,
"file": "C",
"start": 56
},
"type": "CodeGenerationError"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ contract C {
// SMTEngine: all
// ----
// Info 1391: CHC: 1 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them.
// UnimplementedFeatureError 1834: Not yet implemented - FixedPointType.
// UnimplementedFeatureError 1834: (0-80): Not yet implemented - FixedPointType.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ contract C {
}

// ----
// UnimplementedFeatureError 1834: Copying nested calldata dynamic arrays to storage is not implemented in the old code generator.
// UnimplementedFeatureError 1834: (35-127): Copying nested calldata dynamic arrays to storage is not implemented in the old code generator.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ contract C {
}

// ----
// UnimplementedFeatureError 1834: Copying nested calldata dynamic arrays to storage is not implemented in the old code generator.
// UnimplementedFeatureError 1834: (35-125): Copying nested calldata dynamic arrays to storage is not implemented in the old code generator.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ contract C {
fixed a4 = 0 / -0.123;
}
// ----
// UnimplementedFeatureError 1834: Not yet implemented - FixedPointType.
// UnimplementedFeatureError 1834: (0-150): Not yet implemented - FixedPointType.
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ contract C {
// Info 4164: (563-574): Inferred type: (bool, word) -> word
// Info 4164: (563-567): Inferred type: (?bm:type, ?bn:type)
// Info 4164: (575-576): Inferred type: (bool, word)
// UnimplementedFeatureError 1834: No support for calling functions pointers yet.
// UnimplementedFeatureError 1834: (267-586): No support for calling functions pointers yet.
2 changes: 1 addition & 1 deletion test/libsolidity/syntaxTests/immutable/no_assignments.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ contract C {
// ====
// optimize-yul: true
// ----
// CodeGenerationError 1284: Some immutables were read from but never assigned, possibly because of optimization.
// CodeGenerationError 1284: (0-168): Some immutables were read from but never assigned, possibly because of optimization.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ contract test {
// ----
// Warning 2072: (50-67): Unused local variable.
// Warning 2018: (20-119): Function state mutability can be restricted to pure
// UnimplementedFeatureError 1834: Not yet implemented - FixedPointType.
// UnimplementedFeatureError 1834: (0-121): Not yet implemented - FixedPointType.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ contract test {
// ----
// Warning 2072: (50-73): Unused local variable.
// Warning 2018: (20-118): Function state mutability can be restricted to pure
// UnimplementedFeatureError 1834: Not yet implemented - FixedPointType.
// UnimplementedFeatureError 1834: (0-120): Not yet implemented - FixedPointType.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ contract test {
}
// ----
// Warning 2018: (20-147): Function state mutability can be restricted to pure
// UnimplementedFeatureError 1834: Not yet implemented - FixedPointType.
// UnimplementedFeatureError 1834: (0-149): Not yet implemented - FixedPointType.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ contract test {
}
// ----
// Warning 2018: (20-104): Function state mutability can be restricted to pure
// UnimplementedFeatureError 1834: Not yet implemented - FixedPointType.
// UnimplementedFeatureError 1834: (0-106): Not yet implemented - FixedPointType.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ contract test {
}
// ----
// Warning 2018: (20-108): Function state mutability can be restricted to pure
// UnimplementedFeatureError 1834: Not yet implemented - FixedPointType.
// UnimplementedFeatureError 1834: (0-110): Not yet implemented - FixedPointType.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ contract test {
}
}
// ----
// UnimplementedFeatureError 1834: Not yet implemented - FixedPointType.
// UnimplementedFeatureError 1834: (0-126): Not yet implemented - FixedPointType.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ contract A {
}
}
// ----
// UnimplementedFeatureError 1834: Not yet implemented - FixedPointType.
// UnimplementedFeatureError 1834: (0-289): Not yet implemented - FixedPointType.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ contract test {
}
// ----
// Warning 2018: (20-104): Function state mutability can be restricted to pure
// UnimplementedFeatureError 1834: Not yet implemented - FixedPointType.
// UnimplementedFeatureError 1834: (0-106): Not yet implemented - FixedPointType.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ contract test {
}
// ----
// Warning 2018: (20-182): Function state mutability can be restricted to pure
// UnimplementedFeatureError 1834: Not yet implemented - FixedPointType.
// UnimplementedFeatureError 1834: (0-184): Not yet implemented - FixedPointType.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ contract test {
}
}
// ----
// UnimplementedFeatureError 1834: Not yet implemented - FixedPointType.
// UnimplementedFeatureError 1834: (0-130): Not yet implemented - FixedPointType.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ contract test {
myStruct a = myStruct(3.125, 3);
}
// ----
// UnimplementedFeatureError 1834: Not yet implemented - FixedPointType.
// UnimplementedFeatureError 1834: (0-115): Not yet implemented - FixedPointType.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ contract test {
// ----
// Warning 2519: (238-252): This declaration shadows an existing declaration.
// Warning 2018: (20-339): Function state mutability can be restricted to pure
// UnimplementedFeatureError 1834: Not yet implemented - FixedPointType.
// UnimplementedFeatureError 1834: (0-341): Not yet implemented - FixedPointType.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ contract test {
// ----
// Warning 2072: (50-58): Unused local variable.
// Warning 2018: (20-89): Function state mutability can be restricted to pure
// UnimplementedFeatureError 1834: Not yet implemented - FixedPointType.
// UnimplementedFeatureError 1834: (0-91): Not yet implemented - FixedPointType.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ contract A {
// Warning 2072: (93-104): Unused local variable.
// Warning 2072: (114-121): Unused local variable.
// Warning 2018: (41-128): Function state mutability can be restricted to pure
// UnimplementedFeatureError 1834: Fixed point types not implemented.
// UnimplementedFeatureError 1834: (0-130): Fixed point types not implemented.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ contract C {
}
}
// ----
// UnimplementedFeatureError 1834: Not yet implemented - FixedPointType.
// UnimplementedFeatureError 1834: (0-109): Not yet implemented - FixedPointType.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ contract C {
}
}
// ----
// UnimplementedFeatureError 1834: Not yet implemented - FixedPointType.
// UnimplementedFeatureError 1834: (0-317): Not yet implemented - FixedPointType.

0 comments on commit 2ccf0df

Please sign in to comment.