1 //===-- ubsan_handlers.cc -------------------------------------------------===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // Error logging entry points for the UBSan runtime.
10 //===----------------------------------------------------------------------===//
12 #include "ubsan_platform.h"
14 #include "ubsan_handlers.h"
15 #include "ubsan_diag.h"
17 #include "sanitizer_common/sanitizer_common.h"
19 using namespace __sanitizer
;
20 using namespace __ubsan
;
23 bool ignoreReport(SourceLocation SLoc
, ReportOptions Opts
, ErrorType ET
) {
24 // We are not allowed to skip error report: if we are in unrecoverable
25 // handler, we have to terminate the program right now, and therefore
26 // have to print some diagnostic.
28 // Even if source location is disabled, it doesn't mean that we have
29 // already report an error to the user: some concurrently running
30 // thread could have acquired it, but not yet printed the report.
31 if (Opts
.FromUnrecoverableHandler
)
33 return SLoc
.isDisabled() || IsPCSuppressed(ET
, Opts
.pc
, SLoc
.getFilename());
36 const char *TypeCheckKinds
[] = {
37 "load of", "store to", "reference binding to", "member access within",
38 "member call on", "constructor call on", "downcast of", "downcast of",
39 "upcast of", "cast to virtual base of", "_Nonnull binding to"};
42 static void handleTypeMismatchImpl(TypeMismatchData
*Data
, ValueHandle Pointer
,
44 Location Loc
= Data
->Loc
.acquire();
46 uptr Alignment
= (uptr
)1 << Data
->LogAlignment
;
49 ET
= ErrorType::NullPointerUse
;
50 else if (Pointer
& (Alignment
- 1))
51 ET
= ErrorType::MisalignedPointerUse
;
53 ET
= ErrorType::InsufficientObjectSize
;
55 // Use the SourceLocation from Data to track deduplication, even if it's
57 if (ignoreReport(Loc
.getSourceLocation(), Opts
, ET
))
60 SymbolizedStackHolder FallbackLoc
;
61 if (Data
->Loc
.isInvalid()) {
62 FallbackLoc
.reset(getCallerLocation(Opts
.pc
));
66 ScopedReport
R(Opts
, Loc
, ET
);
69 case ErrorType::NullPointerUse
:
70 Diag(Loc
, DL_Error
, "%0 null pointer of type %1")
71 << TypeCheckKinds
[Data
->TypeCheckKind
] << Data
->Type
;
73 case ErrorType::MisalignedPointerUse
:
74 Diag(Loc
, DL_Error
, "%0 misaligned address %1 for type %3, "
75 "which requires %2 byte alignment")
76 << TypeCheckKinds
[Data
->TypeCheckKind
] << (void *)Pointer
<< Alignment
79 case ErrorType::InsufficientObjectSize
:
80 Diag(Loc
, DL_Error
, "%0 address %1 with insufficient space "
81 "for an object of type %2")
82 << TypeCheckKinds
[Data
->TypeCheckKind
] << (void *)Pointer
<< Data
->Type
;
85 UNREACHABLE("unexpected error type!");
89 Diag(Pointer
, DL_Note
, "pointer points here");
92 void __ubsan::__ubsan_handle_type_mismatch_v1(TypeMismatchData
*Data
,
93 ValueHandle Pointer
) {
94 GET_REPORT_OPTIONS(false);
95 handleTypeMismatchImpl(Data
, Pointer
, Opts
);
97 void __ubsan::__ubsan_handle_type_mismatch_v1_abort(TypeMismatchData
*Data
,
98 ValueHandle Pointer
) {
99 GET_REPORT_OPTIONS(true);
100 handleTypeMismatchImpl(Data
, Pointer
, Opts
);
104 /// \brief Common diagnostic emission for various forms of integer overflow.
105 template <typename T
>
106 static void handleIntegerOverflowImpl(OverflowData
*Data
, ValueHandle LHS
,
107 const char *Operator
, T RHS
,
108 ReportOptions Opts
) {
109 SourceLocation Loc
= Data
->Loc
.acquire();
110 bool IsSigned
= Data
->Type
.isSignedIntegerTy();
111 ErrorType ET
= IsSigned
? ErrorType::SignedIntegerOverflow
112 : ErrorType::UnsignedIntegerOverflow
;
114 if (ignoreReport(Loc
, Opts
, ET
))
117 ScopedReport
R(Opts
, Loc
, ET
);
119 Diag(Loc
, DL_Error
, "%0 integer overflow: "
120 "%1 %2 %3 cannot be represented in type %4")
121 << (IsSigned
? "signed" : "unsigned")
122 << Value(Data
->Type
, LHS
) << Operator
<< RHS
<< Data
->Type
;
125 #define UBSAN_OVERFLOW_HANDLER(handler_name, op, unrecoverable) \
126 void __ubsan::handler_name(OverflowData *Data, ValueHandle LHS, \
128 GET_REPORT_OPTIONS(unrecoverable); \
129 handleIntegerOverflowImpl(Data, LHS, op, Value(Data->Type, RHS), Opts); \
134 UBSAN_OVERFLOW_HANDLER(__ubsan_handle_add_overflow
, "+", false)
135 UBSAN_OVERFLOW_HANDLER(__ubsan_handle_add_overflow_abort
, "+", true)
136 UBSAN_OVERFLOW_HANDLER(__ubsan_handle_sub_overflow
, "-", false)
137 UBSAN_OVERFLOW_HANDLER(__ubsan_handle_sub_overflow_abort
, "-", true)
138 UBSAN_OVERFLOW_HANDLER(__ubsan_handle_mul_overflow
, "*", false)
139 UBSAN_OVERFLOW_HANDLER(__ubsan_handle_mul_overflow_abort
, "*", true)
141 static void handleNegateOverflowImpl(OverflowData
*Data
, ValueHandle OldVal
,
142 ReportOptions Opts
) {
143 SourceLocation Loc
= Data
->Loc
.acquire();
144 bool IsSigned
= Data
->Type
.isSignedIntegerTy();
145 ErrorType ET
= IsSigned
? ErrorType::SignedIntegerOverflow
146 : ErrorType::UnsignedIntegerOverflow
;
148 if (ignoreReport(Loc
, Opts
, ET
))
151 ScopedReport
R(Opts
, Loc
, ET
);
155 "negation of %0 cannot be represented in type %1; "
156 "cast to an unsigned type to negate this value to itself")
157 << Value(Data
->Type
, OldVal
) << Data
->Type
;
159 Diag(Loc
, DL_Error
, "negation of %0 cannot be represented in type %1")
160 << Value(Data
->Type
, OldVal
) << Data
->Type
;
163 void __ubsan::__ubsan_handle_negate_overflow(OverflowData
*Data
,
164 ValueHandle OldVal
) {
165 GET_REPORT_OPTIONS(false);
166 handleNegateOverflowImpl(Data
, OldVal
, Opts
);
168 void __ubsan::__ubsan_handle_negate_overflow_abort(OverflowData
*Data
,
169 ValueHandle OldVal
) {
170 GET_REPORT_OPTIONS(true);
171 handleNegateOverflowImpl(Data
, OldVal
, Opts
);
175 static void handleDivremOverflowImpl(OverflowData
*Data
, ValueHandle LHS
,
176 ValueHandle RHS
, ReportOptions Opts
) {
177 SourceLocation Loc
= Data
->Loc
.acquire();
178 Value
LHSVal(Data
->Type
, LHS
);
179 Value
RHSVal(Data
->Type
, RHS
);
182 if (RHSVal
.isMinusOne())
183 ET
= ErrorType::SignedIntegerOverflow
;
184 else if (Data
->Type
.isIntegerTy())
185 ET
= ErrorType::IntegerDivideByZero
;
187 ET
= ErrorType::FloatDivideByZero
;
189 if (ignoreReport(Loc
, Opts
, ET
))
192 ScopedReport
R(Opts
, Loc
, ET
);
195 case ErrorType::SignedIntegerOverflow
:
196 Diag(Loc
, DL_Error
, "division of %0 by -1 cannot be represented in type %1")
197 << LHSVal
<< Data
->Type
;
200 Diag(Loc
, DL_Error
, "division by zero");
205 void __ubsan::__ubsan_handle_divrem_overflow(OverflowData
*Data
,
206 ValueHandle LHS
, ValueHandle RHS
) {
207 GET_REPORT_OPTIONS(false);
208 handleDivremOverflowImpl(Data
, LHS
, RHS
, Opts
);
210 void __ubsan::__ubsan_handle_divrem_overflow_abort(OverflowData
*Data
,
213 GET_REPORT_OPTIONS(true);
214 handleDivremOverflowImpl(Data
, LHS
, RHS
, Opts
);
218 static void handleShiftOutOfBoundsImpl(ShiftOutOfBoundsData
*Data
,
219 ValueHandle LHS
, ValueHandle RHS
,
220 ReportOptions Opts
) {
221 SourceLocation Loc
= Data
->Loc
.acquire();
222 Value
LHSVal(Data
->LHSType
, LHS
);
223 Value
RHSVal(Data
->RHSType
, RHS
);
226 if (RHSVal
.isNegative() ||
227 RHSVal
.getPositiveIntValue() >= Data
->LHSType
.getIntegerBitWidth())
228 ET
= ErrorType::InvalidShiftExponent
;
230 ET
= ErrorType::InvalidShiftBase
;
232 if (ignoreReport(Loc
, Opts
, ET
))
235 ScopedReport
R(Opts
, Loc
, ET
);
237 if (ET
== ErrorType::InvalidShiftExponent
) {
238 if (RHSVal
.isNegative())
239 Diag(Loc
, DL_Error
, "shift exponent %0 is negative") << RHSVal
;
241 Diag(Loc
, DL_Error
, "shift exponent %0 is too large for %1-bit type %2")
242 << RHSVal
<< Data
->LHSType
.getIntegerBitWidth() << Data
->LHSType
;
244 if (LHSVal
.isNegative())
245 Diag(Loc
, DL_Error
, "left shift of negative value %0") << LHSVal
;
248 "left shift of %0 by %1 places cannot be represented in type %2")
249 << LHSVal
<< RHSVal
<< Data
->LHSType
;
253 void __ubsan::__ubsan_handle_shift_out_of_bounds(ShiftOutOfBoundsData
*Data
,
256 GET_REPORT_OPTIONS(false);
257 handleShiftOutOfBoundsImpl(Data
, LHS
, RHS
, Opts
);
259 void __ubsan::__ubsan_handle_shift_out_of_bounds_abort(
260 ShiftOutOfBoundsData
*Data
,
263 GET_REPORT_OPTIONS(true);
264 handleShiftOutOfBoundsImpl(Data
, LHS
, RHS
, Opts
);
268 static void handleOutOfBoundsImpl(OutOfBoundsData
*Data
, ValueHandle Index
,
269 ReportOptions Opts
) {
270 SourceLocation Loc
= Data
->Loc
.acquire();
271 ErrorType ET
= ErrorType::OutOfBoundsIndex
;
273 if (ignoreReport(Loc
, Opts
, ET
))
276 ScopedReport
R(Opts
, Loc
, ET
);
278 Value
IndexVal(Data
->IndexType
, Index
);
279 Diag(Loc
, DL_Error
, "index %0 out of bounds for type %1")
280 << IndexVal
<< Data
->ArrayType
;
283 void __ubsan::__ubsan_handle_out_of_bounds(OutOfBoundsData
*Data
,
285 GET_REPORT_OPTIONS(false);
286 handleOutOfBoundsImpl(Data
, Index
, Opts
);
288 void __ubsan::__ubsan_handle_out_of_bounds_abort(OutOfBoundsData
*Data
,
290 GET_REPORT_OPTIONS(true);
291 handleOutOfBoundsImpl(Data
, Index
, Opts
);
295 static void handleBuiltinUnreachableImpl(UnreachableData
*Data
,
296 ReportOptions Opts
) {
297 ScopedReport
R(Opts
, Data
->Loc
, ErrorType::UnreachableCall
);
298 Diag(Data
->Loc
, DL_Error
, "execution reached a __builtin_unreachable() call");
301 void __ubsan::__ubsan_handle_builtin_unreachable(UnreachableData
*Data
) {
302 GET_REPORT_OPTIONS(true);
303 handleBuiltinUnreachableImpl(Data
, Opts
);
307 static void handleMissingReturnImpl(UnreachableData
*Data
, ReportOptions Opts
) {
308 ScopedReport
R(Opts
, Data
->Loc
, ErrorType::MissingReturn
);
309 Diag(Data
->Loc
, DL_Error
,
310 "execution reached the end of a value-returning function "
311 "without returning a value");
314 void __ubsan::__ubsan_handle_missing_return(UnreachableData
*Data
) {
315 GET_REPORT_OPTIONS(true);
316 handleMissingReturnImpl(Data
, Opts
);
320 static void handleVLABoundNotPositive(VLABoundData
*Data
, ValueHandle Bound
,
321 ReportOptions Opts
) {
322 SourceLocation Loc
= Data
->Loc
.acquire();
323 ErrorType ET
= ErrorType::NonPositiveVLAIndex
;
325 if (ignoreReport(Loc
, Opts
, ET
))
328 ScopedReport
R(Opts
, Loc
, ET
);
330 Diag(Loc
, DL_Error
, "variable length array bound evaluates to "
331 "non-positive value %0")
332 << Value(Data
->Type
, Bound
);
335 void __ubsan::__ubsan_handle_vla_bound_not_positive(VLABoundData
*Data
,
337 GET_REPORT_OPTIONS(false);
338 handleVLABoundNotPositive(Data
, Bound
, Opts
);
340 void __ubsan::__ubsan_handle_vla_bound_not_positive_abort(VLABoundData
*Data
,
342 GET_REPORT_OPTIONS(true);
343 handleVLABoundNotPositive(Data
, Bound
, Opts
);
347 static bool looksLikeFloatCastOverflowDataV1(void *Data
) {
348 // First field is either a pointer to filename or a pointer to a
350 u8
*FilenameOrTypeDescriptor
;
351 internal_memcpy(&FilenameOrTypeDescriptor
, Data
,
352 sizeof(FilenameOrTypeDescriptor
));
354 // Heuristic: For float_cast_overflow, the TypeKind will be either TK_Integer
355 // (0x0), TK_Float (0x1) or TK_Unknown (0xff). If both types are known,
356 // adding both bytes will be 0 or 1 (for BE or LE). If it were a filename,
357 // adding two printable characters will not yield such a value. Otherwise,
358 // if one of them is 0xff, this is most likely TK_Unknown type descriptor.
359 u16 MaybeFromTypeKind
=
360 FilenameOrTypeDescriptor
[0] + FilenameOrTypeDescriptor
[1];
361 return MaybeFromTypeKind
< 2 || FilenameOrTypeDescriptor
[0] == 0xff ||
362 FilenameOrTypeDescriptor
[1] == 0xff;
365 static void handleFloatCastOverflow(void *DataPtr
, ValueHandle From
,
366 ReportOptions Opts
) {
367 SymbolizedStackHolder CallerLoc
;
369 const TypeDescriptor
*FromType
, *ToType
;
370 ErrorType ET
= ErrorType::FloatCastOverflow
;
372 if (looksLikeFloatCastOverflowDataV1(DataPtr
)) {
373 auto Data
= reinterpret_cast<FloatCastOverflowData
*>(DataPtr
);
374 CallerLoc
.reset(getCallerLocation(Opts
.pc
));
376 FromType
= &Data
->FromType
;
377 ToType
= &Data
->ToType
;
379 auto Data
= reinterpret_cast<FloatCastOverflowDataV2
*>(DataPtr
);
380 SourceLocation SLoc
= Data
->Loc
.acquire();
381 if (ignoreReport(SLoc
, Opts
, ET
))
384 FromType
= &Data
->FromType
;
385 ToType
= &Data
->ToType
;
388 ScopedReport
R(Opts
, Loc
, ET
);
391 "%0 is outside the range of representable values of type %2")
392 << Value(*FromType
, From
) << *FromType
<< *ToType
;
395 void __ubsan::__ubsan_handle_float_cast_overflow(void *Data
, ValueHandle From
) {
396 GET_REPORT_OPTIONS(false);
397 handleFloatCastOverflow(Data
, From
, Opts
);
399 void __ubsan::__ubsan_handle_float_cast_overflow_abort(void *Data
,
401 GET_REPORT_OPTIONS(true);
402 handleFloatCastOverflow(Data
, From
, Opts
);
406 static void handleLoadInvalidValue(InvalidValueData
*Data
, ValueHandle Val
,
407 ReportOptions Opts
) {
408 SourceLocation Loc
= Data
->Loc
.acquire();
409 // This check could be more precise if we used different handlers for
410 // -fsanitize=bool and -fsanitize=enum.
411 bool IsBool
= (0 == internal_strcmp(Data
->Type
.getTypeName(), "'bool'")) ||
412 (0 == internal_strncmp(Data
->Type
.getTypeName(), "'BOOL'", 6));
414 IsBool
? ErrorType::InvalidBoolLoad
: ErrorType::InvalidEnumLoad
;
416 if (ignoreReport(Loc
, Opts
, ET
))
419 ScopedReport
R(Opts
, Loc
, ET
);
422 "load of value %0, which is not a valid value for type %1")
423 << Value(Data
->Type
, Val
) << Data
->Type
;
426 void __ubsan::__ubsan_handle_load_invalid_value(InvalidValueData
*Data
,
428 GET_REPORT_OPTIONS(false);
429 handleLoadInvalidValue(Data
, Val
, Opts
);
431 void __ubsan::__ubsan_handle_load_invalid_value_abort(InvalidValueData
*Data
,
433 GET_REPORT_OPTIONS(true);
434 handleLoadInvalidValue(Data
, Val
, Opts
);
438 static void handleInvalidBuiltin(InvalidBuiltinData
*Data
, ReportOptions Opts
) {
439 SourceLocation Loc
= Data
->Loc
.acquire();
440 ErrorType ET
= ErrorType::InvalidBuiltin
;
442 if (ignoreReport(Loc
, Opts
, ET
))
445 ScopedReport
R(Opts
, Loc
, ET
);
448 "passing zero to %0, which is not a valid argument")
449 << ((Data
->Kind
== BCK_CTZPassedZero
) ? "ctz()" : "clz()");
452 void __ubsan::__ubsan_handle_invalid_builtin(InvalidBuiltinData
*Data
) {
453 GET_REPORT_OPTIONS(true);
454 handleInvalidBuiltin(Data
, Opts
);
456 void __ubsan::__ubsan_handle_invalid_builtin_abort(InvalidBuiltinData
*Data
) {
457 GET_REPORT_OPTIONS(true);
458 handleInvalidBuiltin(Data
, Opts
);
462 static void handleFunctionTypeMismatch(FunctionTypeMismatchData
*Data
,
463 ValueHandle Function
,
464 ReportOptions Opts
) {
465 SourceLocation CallLoc
= Data
->Loc
.acquire();
466 ErrorType ET
= ErrorType::FunctionTypeMismatch
;
468 if (ignoreReport(CallLoc
, Opts
, ET
))
471 ScopedReport
R(Opts
, CallLoc
, ET
);
473 SymbolizedStackHolder
FLoc(getSymbolizedLocation(Function
));
474 const char *FName
= FLoc
.get()->info
.function
;
478 Diag(CallLoc
, DL_Error
,
479 "call to function %0 through pointer to incorrect function type %1")
480 << FName
<< Data
->Type
;
481 Diag(FLoc
, DL_Note
, "%0 defined here") << FName
;
485 __ubsan::__ubsan_handle_function_type_mismatch(FunctionTypeMismatchData
*Data
,
486 ValueHandle Function
) {
487 GET_REPORT_OPTIONS(false);
488 handleFunctionTypeMismatch(Data
, Function
, Opts
);
491 void __ubsan::__ubsan_handle_function_type_mismatch_abort(
492 FunctionTypeMismatchData
*Data
, ValueHandle Function
) {
493 GET_REPORT_OPTIONS(true);
494 handleFunctionTypeMismatch(Data
, Function
, Opts
);
498 static void handleNonNullReturn(NonNullReturnData
*Data
, SourceLocation
*LocPtr
,
499 ReportOptions Opts
, bool IsAttr
) {
501 UNREACHABLE("source location pointer is null!");
503 SourceLocation Loc
= LocPtr
->acquire();
504 ErrorType ET
= ErrorType::InvalidNullReturn
;
506 if (ignoreReport(Loc
, Opts
, ET
))
509 ScopedReport
R(Opts
, Loc
, ET
);
511 Diag(Loc
, DL_Error
, "null pointer returned from function declared to never "
513 if (!Data
->AttrLoc
.isInvalid())
514 Diag(Data
->AttrLoc
, DL_Note
, "%0 specified here")
515 << (IsAttr
? "returns_nonnull attribute"
516 : "_Nonnull return type annotation");
519 void __ubsan::__ubsan_handle_nonnull_return_v1(NonNullReturnData
*Data
,
520 SourceLocation
*LocPtr
) {
521 GET_REPORT_OPTIONS(false);
522 handleNonNullReturn(Data
, LocPtr
, Opts
, true);
525 void __ubsan::__ubsan_handle_nonnull_return_v1_abort(NonNullReturnData
*Data
,
526 SourceLocation
*LocPtr
) {
527 GET_REPORT_OPTIONS(true);
528 handleNonNullReturn(Data
, LocPtr
, Opts
, true);
532 void __ubsan::__ubsan_handle_nullability_return_v1(NonNullReturnData
*Data
,
533 SourceLocation
*LocPtr
) {
534 GET_REPORT_OPTIONS(false);
535 handleNonNullReturn(Data
, LocPtr
, Opts
, false);
538 void __ubsan::__ubsan_handle_nullability_return_v1_abort(
539 NonNullReturnData
*Data
, SourceLocation
*LocPtr
) {
540 GET_REPORT_OPTIONS(true);
541 handleNonNullReturn(Data
, LocPtr
, Opts
, false);
545 static void handleNonNullArg(NonNullArgData
*Data
, ReportOptions Opts
,
547 SourceLocation Loc
= Data
->Loc
.acquire();
548 ErrorType ET
= ErrorType::InvalidNullArgument
;
550 if (ignoreReport(Loc
, Opts
, ET
))
553 ScopedReport
R(Opts
, Loc
, ET
);
556 "null pointer passed as argument %0, which is declared to "
559 if (!Data
->AttrLoc
.isInvalid())
560 Diag(Data
->AttrLoc
, DL_Note
, "%0 specified here")
561 << (IsAttr
? "nonnull attribute" : "_Nonnull type annotation");
564 void __ubsan::__ubsan_handle_nonnull_arg(NonNullArgData
*Data
) {
565 GET_REPORT_OPTIONS(false);
566 handleNonNullArg(Data
, Opts
, true);
569 void __ubsan::__ubsan_handle_nonnull_arg_abort(NonNullArgData
*Data
) {
570 GET_REPORT_OPTIONS(true);
571 handleNonNullArg(Data
, Opts
, true);
575 void __ubsan::__ubsan_handle_nullability_arg(NonNullArgData
*Data
) {
576 GET_REPORT_OPTIONS(false);
577 handleNonNullArg(Data
, Opts
, false);
580 void __ubsan::__ubsan_handle_nullability_arg_abort(NonNullArgData
*Data
) {
581 GET_REPORT_OPTIONS(true);
582 handleNonNullArg(Data
, Opts
, false);
586 static void handlePointerOverflowImpl(PointerOverflowData
*Data
,
589 ReportOptions Opts
) {
590 SourceLocation Loc
= Data
->Loc
.acquire();
591 ErrorType ET
= ErrorType::PointerOverflow
;
593 if (ignoreReport(Loc
, Opts
, ET
))
596 ScopedReport
R(Opts
, Loc
, ET
);
598 if ((sptr(Base
) >= 0) == (sptr(Result
) >= 0)) {
600 Diag(Loc
, DL_Error
, "addition of unsigned offset to %0 overflowed to %1")
601 << (void *)Base
<< (void *)Result
;
604 "subtraction of unsigned offset from %0 overflowed to %1")
605 << (void *)Base
<< (void *)Result
;
608 "pointer index expression with base %0 overflowed to %1")
609 << (void *)Base
<< (void *)Result
;
613 void __ubsan::__ubsan_handle_pointer_overflow(PointerOverflowData
*Data
,
615 ValueHandle Result
) {
616 GET_REPORT_OPTIONS(false);
617 handlePointerOverflowImpl(Data
, Base
, Result
, Opts
);
620 void __ubsan::__ubsan_handle_pointer_overflow_abort(PointerOverflowData
*Data
,
622 ValueHandle Result
) {
623 GET_REPORT_OPTIONS(true);
624 handlePointerOverflowImpl(Data
, Base
, Result
, Opts
);
628 static void handleCFIBadIcall(CFICheckFailData
*Data
, ValueHandle Function
,
629 ReportOptions Opts
) {
630 if (Data
->CheckKind
!= CFITCK_ICall
)
633 SourceLocation Loc
= Data
->Loc
.acquire();
634 ErrorType ET
= ErrorType::CFIBadType
;
636 if (ignoreReport(Loc
, Opts
, ET
))
639 ScopedReport
R(Opts
, Loc
, ET
);
641 Diag(Loc
, DL_Error
, "control flow integrity check for type %0 failed during "
642 "indirect function call")
645 SymbolizedStackHolder
FLoc(getSymbolizedLocation(Function
));
646 const char *FName
= FLoc
.get()->info
.function
;
649 Diag(FLoc
, DL_Note
, "%0 defined here") << FName
;
654 #ifdef UBSAN_CAN_USE_CXXABI
658 extern "C" void __ubsan_handle_cfi_bad_type_default(CFICheckFailData
*Data
,
661 ReportOptions Opts
) {
665 WIN_WEAK_ALIAS(__ubsan_handle_cfi_bad_type
, __ubsan_handle_cfi_bad_type_default
)
667 SANITIZER_WEAK_ATTRIBUTE
669 void __ubsan_handle_cfi_bad_type(CFICheckFailData
*Data
, ValueHandle Vtable
,
670 bool ValidVtable
, ReportOptions Opts
);
673 void __ubsan_handle_cfi_bad_type(CFICheckFailData
*Data
, ValueHandle Vtable
,
674 bool ValidVtable
, ReportOptions Opts
) {
679 } // namespace __ubsan
681 void __ubsan::__ubsan_handle_cfi_check_fail(CFICheckFailData
*Data
,
684 GET_REPORT_OPTIONS(false);
685 if (Data
->CheckKind
== CFITCK_ICall
)
686 handleCFIBadIcall(Data
, Value
, Opts
);
688 __ubsan_handle_cfi_bad_type(Data
, Value
, ValidVtable
, Opts
);
691 void __ubsan::__ubsan_handle_cfi_check_fail_abort(CFICheckFailData
*Data
,
694 GET_REPORT_OPTIONS(true);
695 if (Data
->CheckKind
== CFITCK_ICall
)
696 handleCFIBadIcall(Data
, Value
, Opts
);
698 __ubsan_handle_cfi_bad_type(Data
, Value
, ValidVtable
, Opts
);
702 #endif // CAN_SANITIZE_UB