Index: lib/ubsan/ubsan_handlers.cc =================================================================== --- lib/ubsan/ubsan_handlers.cc +++ lib/ubsan/ubsan_handlers.cc @@ -566,8 +566,14 @@ ScopedReport R(Opts, Loc, ET); - Diag(Loc, DL_Error, "pointer index expression with base %0 overflowed to %1") - << (void *)Base << (void*)Result; + if ((sptr(Base) > 0) == (sptr(Result) > 0)) + Diag(Loc, DL_Error, "unsigned pointer index expression result is %0, " + "preceding its base %1") + << (void *)Result << (void *)Base; + else + Diag(Loc, DL_Error, + "pointer index expression with base %0 overflowed to %1") + << (void *)Base << (void *)Result; } void __ubsan::__ubsan_handle_pointer_overflow(PointerOverflowData *Data, Index: test/ubsan/TestCases/Pointer/unsigned-index-expression.cpp =================================================================== --- /dev/null +++ test/ubsan/TestCases/Pointer/unsigned-index-expression.cpp @@ -0,0 +1,12 @@ +// RUN: %clangxx -fsanitize=pointer-overflow %s -o %t +// RUN: %t 2>&1 | FileCheck %s + +int main(int argc, char *argv[]) { + unsigned long long offset = -1; + char *p = (char *)7; + + // CHECK: runtime error: unsigned pointer index expression result is 0x{{0+}}6, preceding its base 0x{{0+}}7 + char *q = p + offset; + + return 0; +}