Skip to content

Commit d6a54ad

Browse files
committed
Revert unneeded changes
1 parent 4110867 commit d6a54ad

23 files changed

+100
-423
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
12841284
getPointerAuthVTablePointerDiscriminator(const CXXRecordDecl *RD);
12851285

12861286
/// Return the "other" type-specific discriminator for the given type.
1287-
uint16_t getPointerAuthTypeDiscriminator(QualType T);
1287+
uint16_t getPointerAuthTypeDiscriminator(QualType T) const;
12881288

12891289
/// Apply Objective-C protocol qualifiers to the given type.
12901290
/// \param allowOnPointerType specifies if we can apply protocol

clang/include/clang/AST/Type.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2507,7 +2507,6 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
25072507
bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); }
25082508
bool isPointerType() const;
25092509
bool isSignableType() const;
2510-
bool isSignablePointerType() const;
25112510
bool isAnyPointerType() const; // Any C pointer or ObjC object pointer
25122511
bool isCountAttributedType() const;
25132512
bool isBlockPointerType() const;
@@ -8003,9 +8002,7 @@ inline bool Type::isAnyPointerType() const {
80038002
return isPointerType() || isObjCObjectPointerType();
80048003
}
80058004

8006-
inline bool Type::isSignableType() const { return isSignablePointerType(); }
8007-
8008-
inline bool Type::isSignablePointerType() const { return isPointerType(); }
8005+
inline bool Type::isSignableType() const { return isPointerType(); }
80098006

80108007
inline bool Type::isBlockPointerType() const {
80118008
return isa<BlockPointerType>(CanonicalType);

clang/lib/AST/ASTContext.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3400,7 +3400,7 @@ static void encodeTypeForFunctionPointerAuth(const ASTContext &Ctx,
34003400
}
34013401
}
34023402

3403-
uint16_t ASTContext::getPointerAuthTypeDiscriminator(QualType T) {
3403+
uint16_t ASTContext::getPointerAuthTypeDiscriminator(QualType T) const {
34043404
assert(!T->isDependentType() &&
34053405
"cannot compute type discriminator of a dependent type");
34063406

@@ -3410,13 +3410,11 @@ uint16_t ASTContext::getPointerAuthTypeDiscriminator(QualType T) {
34103410
if (T->isFunctionPointerType() || T->isFunctionReferenceType())
34113411
T = T->getPointeeType();
34123412

3413-
if (T->isFunctionType()) {
3413+
if (T->isFunctionType())
34143414
encodeTypeForFunctionPointerAuth(*this, Out, T);
3415-
} else {
3416-
T = T.getUnqualifiedType();
3417-
std::unique_ptr<MangleContext> MC(createMangleContext());
3418-
MC->mangleCanonicalTypeName(T, Out);
3419-
}
3415+
else
3416+
llvm_unreachable(
3417+
"type discrimination of non-function type not implemented yet");
34203418

34213419
return llvm::getPointerAuthStableSipHash(Str);
34223420
}

clang/lib/CodeGen/Address.h

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,6 @@ class Address {
134134
/// The expected IR type of the pointer. Carrying accurate element type
135135
/// information in Address makes it more convenient to work with Address
136136
/// values and allows frontend assertions to catch simple mistakes.
137-
///
138-
/// When the address is a raw pointer, this is currently redundant with the
139-
/// pointer's type, but for signed pointers it is useful if the pointer has
140-
/// been offsetted or cast from the original type.
141137
llvm::Type *ElementType = nullptr;
142138

143139
CharUnits Alignment;
@@ -180,11 +176,6 @@ class Address {
180176
static Address invalid() { return Address(nullptr); }
181177
bool isValid() const { return Pointer.getPointer() != nullptr; }
182178

183-
llvm::Value *getPointerIfNotSigned() const {
184-
assert(isValid() && "pointer isn't valid");
185-
return !isSigned() ? Pointer.getPointer() : nullptr;
186-
}
187-
188179
/// This function is used in situations where the caller is doing some sort of
189180
/// opaque "laundering" of the pointer.
190181
void replaceBasePointer(llvm::Value *P) {
@@ -204,11 +195,6 @@ class Address {
204195
return Pointer.getPointer();
205196
}
206197

207-
llvm::Value *getUnsignedPointer() const {
208-
assert(!isSigned() && "cannot call this function if pointer is signed");
209-
return getBasePointer();
210-
}
211-
212198
/// Return the type of the pointer value.
213199
llvm::PointerType *getType() const {
214200
return llvm::PointerType::get(
@@ -252,14 +238,6 @@ class Address {
252238
return *this;
253239
}
254240

255-
/// Add a constant offset.
256-
void addOffset(CharUnits V, llvm::Type *Ty, CGBuilderTy &Builder);
257-
258-
/// Add a variable offset.
259-
/// \param V An llvm value holding a variable offset.
260-
void addOffset(llvm::Value *V, llvm::Type *Ty, CGBuilderTy &Builder,
261-
CharUnits NewAlignment);
262-
263241
bool hasOffset() const { return Offset; }
264242

265243
llvm::Value *getOffset() const { return Offset; }
@@ -270,9 +248,7 @@ class Address {
270248
/// Return the pointer contained in this class after authenticating it and
271249
/// adding offset to it if necessary.
272250
llvm::Value *emitRawPointer(CodeGenFunction &CGF) const {
273-
if (!isSigned())
274-
return getUnsignedPointer();
275-
return emitRawPointerSlow(CGF);
251+
return getBasePointer();
276252
}
277253

278254
/// Return address with different pointer, but same element type and
@@ -303,9 +279,9 @@ class Address {
303279
};
304280

305281
inline RawAddress::RawAddress(Address Addr)
306-
: PointerAndKnownNonNull(
307-
Addr.isValid() ? Addr.getUnsignedPointer() : nullptr,
308-
Addr.isValid() ? Addr.isKnownNonNull() : NotKnownNonNull),
282+
: PointerAndKnownNonNull(Addr.isValid() ? Addr.getBasePointer() : nullptr,
283+
Addr.isValid() ? Addr.isKnownNonNull()
284+
: NotKnownNonNull),
309285
ElementType(Addr.isValid() ? Addr.getElementType() : nullptr),
310286
Alignment(Addr.isValid() ? Addr.getAlignment() : CharUnits::Zero()) {}
311287

clang/lib/CodeGen/CGBlocks.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,8 +1974,8 @@ CodeGenFunction::GenerateCopyHelperFunction(const CGBlockInfo &blockInfo) {
19741974
// it. It's not quite worth the annoyance to avoid creating it in the
19751975
// first place.
19761976
if (!needsEHCleanup(captureType.isDestructedType()))
1977-
if (auto *I = cast_or_null<llvm::Instruction>(
1978-
dstField.getPointerIfNotSigned()))
1977+
if (auto *I =
1978+
cast_or_null<llvm::Instruction>(dstField.getBasePointer()))
19791979
I->eraseFromParent();
19801980
}
19811981
break;

clang/lib/CodeGen/CGBuilder.h

Lines changed: 32 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "llvm/Analysis/Utils/Local.h"
1616
#include "llvm/IR/DataLayout.h"
1717
#include "llvm/IR/IRBuilder.h"
18-
#include "llvm/IR/Module.h"
1918
#include "llvm/IR/Type.h"
2019

2120
namespace clang {
@@ -57,27 +56,7 @@ class CGBuilderTy : public CGBuilderBaseTy {
5756
CodeGenFunction *getCGF() const { return getInserter().CGF; }
5857

5958
llvm::Value *emitRawPointerFromAddress(Address Addr) const {
60-
if (!Addr.isSigned())
61-
return Addr.getUnsignedPointer();
62-
assert(getCGF() && "CGF not set");
63-
return Addr.emitRawPointerSlow(*getCGF());
64-
}
65-
66-
/// Helper function to compute a GEP's offset and add it to Addr.
67-
Address addGEPOffset(Address Addr, ArrayRef<llvm::Value *> IdxList,
68-
CharUnits Align, bool IsInBounds, const Twine &Name) {
69-
typedef ArrayRef<llvm::Value *>::const_iterator IdxItTy;
70-
typedef llvm::generic_gep_type_iterator<IdxItTy> GEPTypeIt;
71-
const llvm::DataLayout &DL = BB->getParent()->getParent()->getDataLayout();
72-
GEPTypeIt GTI = GEPTypeIt::begin(Addr.getElementType(), IdxList.begin());
73-
IdxItTy IdxBegin = IdxList.begin(), IdxEnd = IdxList.end();
74-
llvm::Type *GEPType = Addr.getType();
75-
SmallString<12> Buffer;
76-
StringRef GEPName = Name.toStringRef(Buffer);
77-
std::pair<llvm::Value *, llvm::Type *> OffsetAndType = llvm::EmitGEPOffset(
78-
this, DL, GTI, IdxBegin, IdxEnd, GEPType, GEPName, IsInBounds, false);
79-
Addr.addOffset(OffsetAndType.first, OffsetAndType.second, *this, Align);
80-
return Addr;
59+
return Addr.getBasePointer();
8160
}
8261

8362
template <bool IsInBounds>
@@ -243,14 +222,11 @@ class CGBuilderTy : public CGBuilderBaseTy {
243222
const llvm::StructLayout *Layout = DL.getStructLayout(ElTy);
244223
auto Offset = CharUnits::fromQuantity(Layout->getElementOffset(Index));
245224

246-
if (!Addr.isSigned())
247-
return Address(CreateStructGEP(Addr.getElementType(),
248-
Addr.getUnsignedPointer(), Index, Name),
249-
ElTy->getElementType(Index),
250-
Addr.getAlignment().alignmentAtOffset(Offset),
251-
Addr.isKnownNonNull());
252-
Addr.addOffset(Offset, ElTy->getTypeAtIndex(Index), *this);
253-
return Addr;
225+
return Address(CreateStructGEP(Addr.getElementType(), Addr.getBasePointer(),
226+
Index, Name),
227+
ElTy->getElementType(Index),
228+
Addr.getAlignment().alignmentAtOffset(Offset),
229+
Addr.isKnownNonNull());
254230
}
255231

256232
/// Given
@@ -268,15 +244,12 @@ class CGBuilderTy : public CGBuilderBaseTy {
268244
CharUnits EltSize =
269245
CharUnits::fromQuantity(DL.getTypeAllocSize(ElTy->getElementType()));
270246

271-
if (!Addr.isSigned())
272-
return Address(
273-
CreateInBoundsGEP(Addr.getElementType(), Addr.getUnsignedPointer(),
274-
{getSize(CharUnits::Zero()), getSize(Index)}, Name),
275-
ElTy->getElementType(),
276-
Addr.getAlignment().alignmentAtOffset(Index * EltSize),
277-
Addr.isKnownNonNull());
278-
Addr.addOffset(Index * EltSize, ElTy, *this);
279-
return Addr;
247+
return Address(
248+
CreateInBoundsGEP(Addr.getElementType(), Addr.getBasePointer(),
249+
{getSize(CharUnits::Zero()), getSize(Index)}, Name),
250+
ElTy->getElementType(),
251+
Addr.getAlignment().alignmentAtOffset(Index * EltSize),
252+
Addr.isKnownNonNull());
280253
}
281254

282255
/// Given
@@ -290,14 +263,10 @@ class CGBuilderTy : public CGBuilderBaseTy {
290263
const llvm::DataLayout &DL = BB->getDataLayout();
291264
CharUnits EltSize = CharUnits::fromQuantity(DL.getTypeAllocSize(ElTy));
292265

293-
if (!Addr.isSigned())
294-
return Address(CreateInBoundsGEP(ElTy, Addr.getUnsignedPointer(),
295-
getSize(Index), Name),
296-
ElTy,
297-
Addr.getAlignment().alignmentAtOffset(Index * EltSize),
298-
Addr.isKnownNonNull());
299-
Addr.addOffset(Index * EltSize, ElTy, *this);
300-
return Addr;
266+
return Address(
267+
CreateInBoundsGEP(ElTy, Addr.getBasePointer(), getSize(Index), Name),
268+
ElTy, Addr.getAlignment().alignmentAtOffset(Index * EltSize),
269+
Addr.isKnownNonNull());
301270
}
302271

303272
/// Given
@@ -311,12 +280,9 @@ class CGBuilderTy : public CGBuilderBaseTy {
311280
const llvm::DataLayout &DL = BB->getDataLayout();
312281
CharUnits EltSize = CharUnits::fromQuantity(DL.getTypeAllocSize(ElTy));
313282

314-
if (!Addr.isSigned())
315-
return Address(
316-
CreateGEP(ElTy, Addr.getUnsignedPointer(), getSize(Index), Name),
317-
ElTy, Addr.getAlignment().alignmentAtOffset(Index * EltSize));
318-
Addr.addOffset(Index * EltSize, ElTy, *this);
319-
return Addr;
283+
return Address(CreateGEP(ElTy, Addr.getBasePointer(), getSize(Index), Name),
284+
Addr.getElementType(),
285+
Addr.getAlignment().alignmentAtOffset(Index * EltSize));
320286
}
321287

322288
/// Create GEP with single dynamic index. The address alignment is reduced
@@ -338,28 +304,20 @@ class CGBuilderTy : public CGBuilderBaseTy {
338304
Address CreateConstInBoundsByteGEP(Address Addr, CharUnits Offset,
339305
const llvm::Twine &Name = "") {
340306
assert(Addr.getElementType() == TypeCache.Int8Ty);
341-
342-
if (!Addr.isSigned())
343-
return Address(
344-
CreateInBoundsGEP(Addr.getElementType(), Addr.getUnsignedPointer(),
345-
getSize(Offset), Name),
346-
Addr.getElementType(), Addr.getAlignment().alignmentAtOffset(Offset),
347-
Addr.isKnownNonNull());
348-
Addr.addOffset(Offset, TypeCache.Int8Ty, *this);
349-
return Addr;
307+
return Address(
308+
CreateInBoundsGEP(Addr.getElementType(), Addr.getBasePointer(),
309+
getSize(Offset), Name),
310+
Addr.getElementType(), Addr.getAlignment().alignmentAtOffset(Offset),
311+
Addr.isKnownNonNull());
350312
}
351313

352314
Address CreateConstByteGEP(Address Addr, CharUnits Offset,
353315
const llvm::Twine &Name = "") {
354316
assert(Addr.getElementType() == TypeCache.Int8Ty);
355-
356-
if (!Addr.isSigned())
357-
return Address(CreateGEP(Addr.getElementType(), Addr.getUnsignedPointer(),
358-
getSize(Offset), Name),
359-
Addr.getElementType(),
360-
Addr.getAlignment().alignmentAtOffset(Offset));
361-
Addr.addOffset(Offset, TypeCache.Int8Ty, *this);
362-
return Addr;
317+
return Address(CreateGEP(Addr.getElementType(), Addr.getBasePointer(),
318+
getSize(Offset), Name),
319+
Addr.getElementType(),
320+
Addr.getAlignment().alignmentAtOffset(Offset));
363321
}
364322

365323
using CGBuilderBaseTy::CreateConstInBoundsGEP2_32;
@@ -386,12 +344,10 @@ class CGBuilderTy : public CGBuilderBaseTy {
386344
Address CreateInBoundsGEP(Address Addr, ArrayRef<llvm::Value *> IdxList,
387345
llvm::Type *ElementType, CharUnits Align,
388346
const Twine &Name = "") {
389-
if (!Addr.isSigned())
390-
return RawAddress(CreateInBoundsGEP(Addr.getElementType(),
391-
emitRawPointerFromAddress(Addr),
392-
IdxList, Name),
393-
ElementType, Align, Addr.isKnownNonNull());
394-
return addGEPOffset(Addr, IdxList, Align, true, Name);
347+
return RawAddress(CreateInBoundsGEP(Addr.getElementType(),
348+
emitRawPointerFromAddress(Addr),
349+
IdxList, Name),
350+
ElementType, Align, Addr.isKnownNonNull());
395351
}
396352

397353
using CGBuilderBaseTy::CreateIsNull;

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,8 +2151,7 @@ RValue CodeGenFunction::emitBuiltinOSLogFormat(const CallExpr &E) {
21512151

21522152
// Ignore argument 1, the format string. It is not currently used.
21532153
CallArgList Args;
2154-
Args.add(RValue::get(getAsNaturalPointerTo(BufAddr, Ctx.VoidTy)),
2155-
Ctx.VoidPtrTy);
2154+
Args.add(RValue::get(BufAddr.emitRawPointer(*this)), Ctx.VoidPtrTy);
21562155

21572156
for (const auto &Item : Layout.Items) {
21582157
int Size = Item.getSizeByte();

clang/lib/CodeGen/CGCall.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3508,8 +3508,7 @@ static llvm::Value *tryRemoveRetainOfSelf(CodeGenFunction &CGF,
35083508
llvm::LoadInst *load =
35093509
dyn_cast<llvm::LoadInst>(retainedValue->stripPointerCasts());
35103510
if (!load || load->isAtomic() || load->isVolatile() ||
3511-
load->getPointerOperand() !=
3512-
CGF.GetAddrOfLocalVar(self).getPointerIfNotSigned())
3511+
load->getPointerOperand() != CGF.GetAddrOfLocalVar(self).getBasePointer())
35133512
return nullptr;
35143513

35153514
// Okay! Burn it all down. This relies for correctness on the
@@ -3546,8 +3545,7 @@ static llvm::Value *emitAutoreleaseOfResult(CodeGenFunction &CGF,
35463545

35473546
/// Heuristically search for a dominating store to the return-value slot.
35483547
static llvm::StoreInst *findDominatingStoreToReturnValue(CodeGenFunction &CGF) {
3549-
// This function shouldn't be called when ReturnValue is signed.
3550-
llvm::Value *ReturnValuePtr = CGF.ReturnValue.getUnsignedPointer();
3548+
llvm::Value *ReturnValuePtr = CGF.ReturnValue.getBasePointer();
35513549

35523550
// Check if a User is a store which pointerOperand is the ReturnValue.
35533551
// We are looking for stores to the ReturnValue, not for stores of the
@@ -4135,16 +4133,15 @@ static bool isProvablyNull(llvm::Value *addr) {
41354133
}
41364134

41374135
static bool isProvablyNonNull(Address Addr, CodeGenFunction &CGF) {
4138-
return !Addr.isSigned() && llvm::isKnownNonZero(Addr.getUnsignedPointer(),
4139-
CGF.CGM.getDataLayout());
4136+
return llvm::isKnownNonZero(Addr.getBasePointer(), CGF.CGM.getDataLayout());
41404137
}
41414138

41424139
/// Emit the actual writing-back of a writeback.
41434140
static void emitWriteback(CodeGenFunction &CGF,
41444141
const CallArgList::Writeback &writeback) {
41454142
const LValue &srcLV = writeback.Source;
41464143
Address srcAddr = srcLV.getAddress();
4147-
assert(!isProvablyNull(srcAddr.getPointerIfNotSigned()) &&
4144+
assert(!isProvablyNull(srcAddr.getBasePointer()) &&
41484145
"shouldn't have writeback for provably null argument");
41494146

41504147
llvm::BasicBlock *contBB = nullptr;
@@ -4261,7 +4258,7 @@ static void emitWritebackArg(CodeGenFunction &CGF, CallArgList &args,
42614258
CGF.ConvertTypeForMem(CRE->getType()->getPointeeType());
42624259

42634260
// If the address is a constant null, just pass the appropriate null.
4264-
if (isProvablyNull(srcAddr.getPointerIfNotSigned())) {
4261+
if (isProvablyNull(srcAddr.getBasePointer())) {
42654262
args.add(RValue::get(llvm::ConstantPointerNull::get(destType)),
42664263
CRE->getType());
42674264
return;
@@ -5101,7 +5098,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
51015098
llvm::Value *UnusedReturnSizePtr = nullptr;
51025099
if (RetAI.isIndirect() || RetAI.isInAlloca() || RetAI.isCoerceAndExpand()) {
51035100
if (!ReturnValue.isNull()) {
5104-
SRetPtr = ReturnValue.getValue();
5101+
SRetPtr = ReturnValue.getAddress();
51055102
} else {
51065103
SRetPtr = CreateMemTemp(RetTy, "tmp", &SRetAlloca);
51075104
if (HaveInsertPoint() && ReturnValue.isUnused()) {

clang/lib/CodeGen/CGException.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,8 +1835,8 @@ Address CodeGenFunction::recoverAddrOfEscapedLocal(CodeGenFunction &ParentCGF,
18351835
llvm::Value *ParentFP) {
18361836
llvm::CallInst *RecoverCall = nullptr;
18371837
CGBuilderTy Builder(*this, AllocaInsertPt);
1838-
if (auto *ParentAlloca = dyn_cast_or_null<llvm::AllocaInst>(
1839-
ParentVar.getPointerIfNotSigned())) {
1838+
if (auto *ParentAlloca =
1839+
dyn_cast_or_null<llvm::AllocaInst>(ParentVar.getBasePointer())) {
18401840
// Mark the variable escaped if nobody else referenced it and compute the
18411841
// localescape index.
18421842
auto InsertPair = ParentCGF.EscapedLocals.insert(

0 commit comments

Comments
 (0)