@@ -131,7 +131,7 @@ SymbolicValue SymbolicValue::getInteger(int64_t value, unsigned bitWidth) {
131
131
SymbolicValue result;
132
132
result.representationKind = RK_IntegerInline;
133
133
result.value .integerInline = value;
134
- result.aux . integer_bitwidth = bitWidth;
134
+ result.auxInfo . integerBitwidth = bitWidth;
135
135
return result;
136
136
}
137
137
@@ -150,28 +150,29 @@ SymbolicValue SymbolicValue::getInteger(const APInt &value,
150
150
SymbolicValue result;
151
151
result.representationKind = RK_Integer;
152
152
result.value .integer = words;
153
- result.aux . integer_bitwidth = value.getBitWidth ();
153
+ result.auxInfo . integerBitwidth = value.getBitWidth ();
154
154
return result;
155
155
}
156
156
157
157
APInt SymbolicValue::getIntegerValue () const {
158
158
assert (getKind () == Integer);
159
159
if (representationKind == RK_IntegerInline) {
160
- auto numBits = aux. integer_bitwidth ;
160
+ auto numBits = auxInfo. integerBitwidth ;
161
161
return APInt (numBits, value.integerInline );
162
162
}
163
163
164
164
assert (representationKind == RK_Integer);
165
- auto numBits = aux.integer_bitwidth ;
166
- auto numWords = (numBits + 63 ) / 64 ;
165
+ auto numBits = auxInfo.integerBitwidth ;
166
+ auto numWords =
167
+ (numBits + APInt::APINT_BITS_PER_WORD - 1 ) / APInt::APINT_BITS_PER_WORD;
167
168
return APInt (numBits, {value.integer , numWords});
168
169
}
169
170
170
171
unsigned SymbolicValue::getIntegerValueBitWidth () const {
171
172
assert (getKind () == Integer);
172
173
assert (representationKind == RK_IntegerInline ||
173
174
representationKind == RK_Integer);
174
- return aux. integer_bitwidth ;
175
+ return auxInfo. integerBitwidth ;
175
176
}
176
177
177
178
// ===----------------------------------------------------------------------===//
@@ -190,13 +191,13 @@ SymbolicValue SymbolicValue::getAggregate(ArrayRef<SymbolicValue> elements,
190
191
SymbolicValue result;
191
192
result.representationKind = RK_Aggregate;
192
193
result.value .aggregate = resultElts;
193
- result.aux . aggregate_numElements = elements.size ();
194
+ result.auxInfo . aggregateNumElements = elements.size ();
194
195
return result;
195
196
}
196
197
197
198
ArrayRef<SymbolicValue> SymbolicValue::getAggregateValue () const {
198
199
assert (getKind () == Aggregate);
199
- return ArrayRef<SymbolicValue>(value.aggregate , aux. aggregate_numElements );
200
+ return ArrayRef<SymbolicValue>(value.aggregate , auxInfo. aggregateNumElements );
200
201
}
201
202
202
203
// ===----------------------------------------------------------------------===//
@@ -217,7 +218,7 @@ struct alignas(SourceLoc) UnknownSymbolicValue final
217
218
UnknownReason reason;
218
219
219
220
// / The number of elements in the call stack.
220
- unsigned call_stack_size ;
221
+ unsigned callStackSize ;
221
222
222
223
static UnknownSymbolicValue *create (SILNode *node, UnknownReason reason,
223
224
ArrayRef<SourceLoc> elements,
@@ -235,20 +236,20 @@ struct alignas(SourceLoc) UnknownSymbolicValue final
235
236
}
236
237
237
238
ArrayRef<SourceLoc> getCallStack () const {
238
- return {getTrailingObjects<SourceLoc>(), call_stack_size };
239
+ return {getTrailingObjects<SourceLoc>(), callStackSize };
239
240
}
240
241
241
242
// This is used by the llvm::TrailingObjects base class.
242
243
size_t numTrailingObjects (OverloadToken<SourceLoc>) const {
243
- return call_stack_size ;
244
+ return callStackSize ;
244
245
}
245
246
246
247
private:
247
248
UnknownSymbolicValue () = delete ;
248
249
UnknownSymbolicValue (const UnknownSymbolicValue &) = delete ;
249
250
UnknownSymbolicValue (SILNode *node, UnknownReason reason,
250
- unsigned call_stack_size )
251
- : node (node), reason (reason), call_stack_size (call_stack_size ) {}
251
+ unsigned callStackSize )
252
+ : node (node), reason (reason), callStackSize (callStackSize ) {}
252
253
};
253
254
} // namespace swift
254
255
@@ -330,7 +331,7 @@ SymbolicValue SymbolicValue::lookThroughSingleElementAggregates() const {
330
331
// / is an interesting SourceLoc to point at.
331
332
// / Returns true if a diagnostic was emitted.
332
333
static bool emitNoteDiagnostic (SILInstruction *badInst, UnknownReason reason,
333
- SILLocation fallbackLoc, std::string error ) {
334
+ SILLocation fallbackLoc) {
334
335
auto loc = skipInternalLocations (badInst->getDebugLocation ()).getLocation ();
335
336
if (loc.isNull ()) {
336
337
// If we have important clarifying information, make sure to emit it.
@@ -339,63 +340,55 @@ static bool emitNoteDiagnostic(SILInstruction *badInst, UnknownReason reason,
339
340
loc = fallbackLoc;
340
341
}
341
342
342
- auto &module = badInst->getModule ();
343
- diagnose (module .getASTContext (), loc.getSourceLoc (),
344
- diag::constexpr_unknown_reason, error)
345
- .highlight (loc.getSourceRange ());
346
- return true ;
347
- }
348
-
349
- // / Given that this is an 'Unknown' value, emit diagnostic notes providing
350
- // / context about what the problem is.
351
- void SymbolicValue::emitUnknownDiagnosticNotes (SILLocation fallbackLoc) {
352
- auto badInst = dyn_cast<SILInstruction>(getUnknownNode ());
353
- if (!badInst)
354
- return ;
355
-
356
- std::string error;
357
- switch (getUnknownReason ()) {
343
+ auto &ctx = badInst->getModule ().getASTContext ();
344
+ auto sourceLoc = loc.getSourceLoc ();
345
+ switch (reason) {
358
346
case UnknownReason::Default:
359
- error = " could not fold operation" ;
347
+ diagnose (ctx, sourceLoc, diag::constexpr_unknown_reason_default)
348
+ .highlight (loc.getSourceRange ());
360
349
break ;
361
350
case UnknownReason::TooManyInstructions:
362
351
// TODO: Should pop up a level of the stack trace.
363
- error = " exceeded instruction limit: " + std::to_string (ConstExprLimit) +
364
- " when evaluating the expression at compile time" ;
352
+ diagnose (ctx, sourceLoc, diag::constexpr_too_many_instructions,
353
+ ConstExprLimit)
354
+ .highlight (loc.getSourceRange ());
365
355
break ;
366
356
case UnknownReason::Loop:
367
- error = " control flow loop found" ;
357
+ diagnose (ctx, sourceLoc, diag::constexpr_loop)
358
+ .highlight (loc.getSourceRange ());
368
359
break ;
369
360
case UnknownReason::Overflow:
370
- error = " integer overflow detected" ;
361
+ diagnose (ctx, sourceLoc, diag::constexpr_overflow)
362
+ .highlight (loc.getSourceRange ());
371
363
break ;
372
364
case UnknownReason::Trap:
373
- error = " trap detected" ;
365
+ diagnose (ctx, sourceLoc, diag::constexpr_trap)
366
+ .highlight (loc.getSourceRange ());
374
367
break ;
375
368
}
369
+ return true ;
370
+ }
371
+
372
+ // / Given that this is an 'Unknown' value, emit diagnostic notes providing
373
+ // / context about what the problem is.
374
+ void SymbolicValue::emitUnknownDiagnosticNotes (SILLocation fallbackLoc) {
375
+ auto badInst = dyn_cast<SILInstruction>(getUnknownNode ());
376
+ if (!badInst)
377
+ return ;
376
378
377
- bool emittedFirstNote =
378
- emitNoteDiagnostic (badInst, getUnknownReason (), fallbackLoc, error );
379
+ bool emittedFirstNote = emitNoteDiagnostic (badInst, getUnknownReason (),
380
+ fallbackLoc );
379
381
380
382
auto sourceLoc = fallbackLoc.getSourceLoc ();
381
383
auto &module = badInst->getModule ();
382
384
if (sourceLoc.isInvalid ()) {
383
385
diagnose (module .getASTContext (), sourceLoc, diag::constexpr_not_evaluable);
384
386
return ;
385
387
}
386
- auto &SM = module .getASTContext ().SourceMgr ;
387
- unsigned originalDiagnosticLineNumber =
388
- SM.getLineNumber (fallbackLoc.getSourceLoc ());
389
388
for (auto &sourceLoc : llvm::reverse (getUnknownCallStack ())) {
390
389
// Skip unknown sources.
391
390
if (!sourceLoc.isValid ())
392
391
continue ;
393
- // Also skip notes that point to the same line as the original error, for
394
- // example in:
395
- // #assert(foo(bar()))
396
- // it is not useful to get three diagnostics referring to the same line.
397
- if (SM.getLineNumber (sourceLoc) == originalDiagnosticLineNumber)
398
- continue ;
399
392
400
393
auto diag = emittedFirstNote ? diag::constexpr_called_from
401
394
: diag::constexpr_not_evaluable;
0 commit comments