Skip to content

Commit 4c9ca1b

Browse files
authored
Fix UBSAN error in iterator.h (microsoft#5794)
Fixes UBSAN error: ``` include/llvm/ADT/iterator.h:171:7: runtime error: applying non-zero offset 8 to null pointer ``` When ULE has no decls, `decls_begin` returns a null-ptr iterator, and adding 1 to this pointer is undefined behaviour. We fix this by adding a check that ULE actually has decls before doing this. Fixes 332 of these reported from running check-all.
1 parent 7640ffa commit 4c9ca1b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

tools/clang/lib/Sema/SemaOverload.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10936,7 +10936,11 @@ bool Sema::buildOverloadedCallSet(Scope *S, Expr *Fn,
1093610936
// We don't perform ADL for implicit declarations of builtins.
1093710937
// Verify that this was correctly set up.
1093810938
FunctionDecl *F;
10939-
if (ULE->decls_begin() + 1 == ULE->decls_end() &&
10939+
if (
10940+
// HLSL change begin
10941+
(ULE->getNumDecls() > 0) &&
10942+
// HLSL change end
10943+
ULE->decls_begin() + 1 == ULE->decls_end() &&
1094010944
(F = dyn_cast<FunctionDecl>(*ULE->decls_begin())) &&
1094110945
F->getBuiltinID() && F->isImplicit())
1094210946
llvm_unreachable("performing ADL for builtin");

0 commit comments

Comments
 (0)