Skip to content

Commit eb9ea2c

Browse files
committed
Tidy
1 parent 4714264 commit eb9ea2c

File tree

4 files changed

+46
-43
lines changed

4 files changed

+46
-43
lines changed

clang/lib/CodeGen/CGExprCXX.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "clang/Basic/SourceManager.h"
2424
#include "clang/CodeGen/CGFunctionInfo.h"
2525
#include "llvm/IR/Intrinsics.h"
26-
#include <cstdio>
2726

2827
using namespace clang;
2928
using namespace CodeGen;
@@ -1743,29 +1742,26 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) {
17431742
// Check what type of constructor call the sanitizer is checking
17441743
// Different UB can occour with custom overloads of operator new
17451744
TypeCheckKind checkKind = CodeGenFunction::TCK_ConstructorCall;
1746-
const TargetInfo& TI = getContext().getTargetInfo();
1745+
const TargetInfo &TI = getContext().getTargetInfo();
17471746
unsigned DefaultTargetAlignment = TI.getNewAlign() / TI.getCharWidth();
17481747
SourceManager &SM = getContext().getSourceManager();
17491748
SourceLocation Loc = E->getOperatorNew()->getLocation();
17501749
bool IsCustomOverload = !SM.isInSystemHeader(Loc);
1751-
if (
1752-
SanOpts.has(SanitizerKind::Alignment) &&
1753-
IsCustomOverload &&
1754-
(DefaultTargetAlignment > CGM.getContext().getTypeAlignInChars(allocType).getQuantity())
1755-
)
1750+
if (SanOpts.has(SanitizerKind::Alignment) && IsCustomOverload &&
1751+
(DefaultTargetAlignment >
1752+
CGM.getContext().getTypeAlignInChars(allocType).getQuantity()))
17561753
checkKind = CodeGenFunction::TCK_ConstructorCallOverloadedNew;
1757-
1754+
17581755
// Emit sanitizer checks for pointer value now, so that in the case of an
17591756
// array it was checked only once and not at each constructor call. We may
17601757
// have already checked that the pointer is non-null.
17611758
// FIXME: If we have an array cookie and a potentially-throwing allocator,
17621759
// we'll null check the wrong pointer here.
17631760
SanitizerSet SkippedChecks;
17641761
SkippedChecks.set(SanitizerKind::Null, nullCheck);
1765-
EmitTypeCheck(checkKind,
1766-
E->getAllocatedTypeSourceInfo()->getTypeLoc().getBeginLoc(),
1767-
result, allocType, result.getAlignment(), SkippedChecks,
1768-
numElements);
1762+
EmitTypeCheck(
1763+
checkKind, E->getAllocatedTypeSourceInfo()->getTypeLoc().getBeginLoc(),
1764+
result, allocType, result.getAlignment(), SkippedChecks, numElements);
17691765

17701766
EmitNewInitializer(*this, E, allocType, elementTy, result, numElements,
17711767
allocSizeWithoutCookie);

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3293,7 +3293,7 @@ class CodeGenFunction : public CodeGenTypeCache {
32933293
/// Checking the operand of a dynamic_cast or a typeid expression. Must be
32943294
/// null or an object within its lifetime.
32953295
TCK_DynamicOperation,
3296-
/// Checking the 'this' poiner for a constructor call, including that the
3296+
/// Checking the 'this' poiner for a constructor call, including that the
32973297
/// alignment is greater or equal to the targets minimum alignment
32983298
TCK_ConstructorCallOverloadedNew
32993299
};

compiler-rt/lib/ubsan/ubsan_handlers.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,25 @@ enum TypeCheckKind {
7474
/// Checking the operand of a dynamic_cast or a typeid expression. Must be
7575
/// null or an object within its lifetime.
7676
TCK_DynamicOperation,
77-
/// Checking the 'this' poiner for a constructor call, including that the
77+
/// Checking the 'this' poiner for a constructor call, including that the
7878
/// alignment is greater or equal to the targets minimum alignment
7979
TCK_ConstructorCallOverloadedNew
8080
};
8181

8282
extern const char *const TypeCheckKinds[] = {
83-
"load of", "store to", "reference binding to", "member access within",
84-
"member call on", "constructor call on", "downcast of", "downcast of",
85-
"upcast of", "cast to virtual base of", "_Nonnull binding to",
86-
"dynamic operation on", "constructor call with pointer from overloaded operator new on"};
83+
"load of",
84+
"store to",
85+
"reference binding to",
86+
"member access within",
87+
"member call on",
88+
"constructor call on",
89+
"downcast of",
90+
"downcast of",
91+
"upcast of",
92+
"cast to virtual base of",
93+
"_Nonnull binding to",
94+
"dynamic operation on",
95+
"constructor call with pointer from overloaded operator new on"};
8796
}
8897

8998
static void handleTypeMismatchImpl(TypeMismatchData *Data, ValueHandle Pointer,
@@ -98,8 +107,8 @@ static void handleTypeMismatchImpl(TypeMismatchData *Data, ValueHandle Pointer,
98107
: ErrorType::NullPointerUse;
99108
else if (Pointer & (Alignment - 1))
100109
ET = (Data->TypeCheckKind == TCK_ConstructorCallOverloadedNew)
101-
? ErrorType::AlignmentOnOverloadedNew
102-
: ErrorType::MisalignedPointerUse;
110+
? ErrorType::AlignmentOnOverloadedNew
111+
: ErrorType::MisalignedPointerUse;
103112
else
104113
ET = ErrorType::InsufficientObjectSize;
105114

@@ -123,10 +132,11 @@ static void handleTypeMismatchImpl(TypeMismatchData *Data, ValueHandle Pointer,
123132
<< TypeCheckKinds[Data->TypeCheckKind] << Data->Type;
124133
break;
125134
case ErrorType::AlignmentOnOverloadedNew:
126-
Diag(Loc, DL_Error, ET, "%0 misaligned address %1 for type %2, "
127-
"which requires target minimum assumed alignment of %3")
128-
<< TypeCheckKinds[Data->TypeCheckKind] << (void *)Pointer
129-
<< Data->Type << Alignment;
135+
Diag(Loc, DL_Error, ET,
136+
"%0 misaligned address %1 for type %2, "
137+
"which requires target minimum assumed alignment of %3")
138+
<< TypeCheckKinds[Data->TypeCheckKind] << (void *)Pointer << Data->Type
139+
<< Alignment;
130140
break;
131141
case ErrorType::MisalignedPointerUse:
132142
Diag(Loc, DL_Error, ET, "%0 misaligned address %1 for type %3, "
Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %clangxx %gmlt -fsanitize=alignment %s -o %t
22
// RUN: %run %t 2>&1 | FileCheck %s
33

4-
// UNSUPPORTED: i386
4+
// UNSUPPORTED: i386
55
// UNSUPPORTED: armv7l
66

77
// These sanitizers already overload the new operator so won't compile this test
@@ -11,29 +11,26 @@
1111
#include <cassert>
1212
#include <cstdlib>
1313

14-
void* operator new(std::size_t count)
15-
{
16-
constexpr const size_t offset = 8;
14+
void *operator new(std::size_t count) {
15+
constexpr const size_t offset = 8;
1716

18-
// allocate a bit more so we can safely offset it
19-
void* ptr = std::malloc(count + offset);
17+
// allocate a bit more so we can safely offset it
18+
void *ptr = std::malloc(count + offset);
2019

21-
// verify malloc returned 16 bytes aligned mem
22-
static_assert(__STDCPP_DEFAULT_NEW_ALIGNMENT__ == 16);
23-
assert(((std::ptrdiff_t)ptr & (__STDCPP_DEFAULT_NEW_ALIGNMENT__ - 1)) == 0);
20+
// verify malloc returned 16 bytes aligned mem
21+
static_assert(__STDCPP_DEFAULT_NEW_ALIGNMENT__ == 16);
22+
assert(((std::ptrdiff_t)ptr & (__STDCPP_DEFAULT_NEW_ALIGNMENT__ - 1)) == 0);
2423

25-
return (char*)ptr + offset;
24+
return (char *)ptr + offset;
2625
}
2726

28-
struct Foo
29-
{
30-
void* _cookie1, *_cookie2;
27+
struct Foo {
28+
void *_cookie1, *_cookie2;
3129
};
3230

3331
static_assert(alignof(Foo) == 8);
34-
int main()
35-
{
36-
// CHECK: runtime error: constructor call with pointer from overloaded operator new on misaligned address 0x{{.*}} for type 'Foo', which requires target minimum assumed alignment of 16
37-
Foo* f = new Foo;
38-
return 0;
39-
}
32+
int main() {
33+
// CHECK: runtime error: constructor call with pointer from overloaded operator new on misaligned address 0x{{.*}} for type 'Foo', which requires target minimum assumed alignment of 16
34+
Foo *f = new Foo;
35+
return 0;
36+
}

0 commit comments

Comments
 (0)