Skip to content

Commit 50a6738

Browse files
authored
[clang][NFC] Adjust TBAA Base Info API (#73263)
A couple of cleanups. 1) remove an unnecessary check from isValidBaseType. 2) Add a new internal entrypoint 'getValidBaseTypeInfo', for uses where the type is known to be valid.
1 parent ac8ed7f commit 50a6738

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

clang/lib/CodeGen/CodeGenTBAA.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ static bool TypeHasMayAlias(QualType QTy) {
9898

9999
/// Check if the given type is a valid base type to be used in access tags.
100100
static bool isValidBaseType(QualType QTy) {
101-
if (QTy->isReferenceType())
102-
return false;
103101
if (const RecordType *TTy = QTy->getAs<RecordType>()) {
104102
const RecordDecl *RD = TTy->getDecl()->getDefinition();
105103
// Incomplete types are not valid base access types.
@@ -243,9 +241,10 @@ llvm::MDNode *CodeGenTBAA::getTypeInfo(QualType QTy) {
243241
// aggregate will result into the may-alias access descriptor, meaning all
244242
// subsequent accesses to direct and indirect members of that aggregate will
245243
// be considered may-alias too.
246-
// TODO: Combine getTypeInfo() and getBaseTypeInfo() into a single function.
244+
// TODO: Combine getTypeInfo() and getValidBaseTypeInfo() into a single
245+
// function.
247246
if (isValidBaseType(QTy))
248-
return getBaseTypeInfo(QTy);
247+
return getValidBaseTypeInfo(QTy);
249248

250249
const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
251250
if (llvm::MDNode *N = MetadataCache[Ty])
@@ -394,7 +393,7 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(const Type *Ty) {
394393
if (BaseRD->isEmpty())
395394
continue;
396395
llvm::MDNode *TypeNode = isValidBaseType(BaseQTy)
397-
? getBaseTypeInfo(BaseQTy)
396+
? getValidBaseTypeInfo(BaseQTy)
398397
: getTypeInfo(BaseQTy);
399398
if (!TypeNode)
400399
return nullptr;
@@ -418,8 +417,9 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(const Type *Ty) {
418417
if (Field->isZeroSize(Context) || Field->isUnnamedBitfield())
419418
continue;
420419
QualType FieldQTy = Field->getType();
421-
llvm::MDNode *TypeNode = isValidBaseType(FieldQTy) ?
422-
getBaseTypeInfo(FieldQTy) : getTypeInfo(FieldQTy);
420+
llvm::MDNode *TypeNode = isValidBaseType(FieldQTy)
421+
? getValidBaseTypeInfo(FieldQTy)
422+
: getTypeInfo(FieldQTy);
423423
if (!TypeNode)
424424
return nullptr;
425425

@@ -456,9 +456,8 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(const Type *Ty) {
456456
return nullptr;
457457
}
458458

459-
llvm::MDNode *CodeGenTBAA::getBaseTypeInfo(QualType QTy) {
460-
if (!isValidBaseType(QTy))
461-
return nullptr;
459+
llvm::MDNode *CodeGenTBAA::getValidBaseTypeInfo(QualType QTy) {
460+
assert(isValidBaseType(QTy) && "Must be a valid base type");
462461

463462
const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
464463

@@ -477,6 +476,10 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfo(QualType QTy) {
477476
return TypeNode;
478477
}
479478

479+
llvm::MDNode *CodeGenTBAA::getBaseTypeInfo(QualType QTy) {
480+
return isValidBaseType(QTy) ? getValidBaseTypeInfo(QTy) : nullptr;
481+
}
482+
480483
llvm::MDNode *CodeGenTBAA::getAccessTagInfo(TBAAAccessInfo Info) {
481484
assert(!Info.isIncomplete() && "Access to an object of an incomplete type!");
482485

clang/lib/CodeGen/CodeGenTBAA.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ class CodeGenTBAA {
168168
/// used to describe accesses to objects of the given base type.
169169
llvm::MDNode *getBaseTypeInfoHelper(const Type *Ty);
170170

171+
/// getValidBaseTypeInfo - Return metadata that describes the given base
172+
/// access type. The type must be suitable.
173+
llvm::MDNode *getValidBaseTypeInfo(QualType QTy);
174+
171175
public:
172176
CodeGenTBAA(ASTContext &Ctx, CodeGenTypes &CGTypes, llvm::Module &M,
173177
const CodeGenOptions &CGO, const LangOptions &Features,
@@ -190,8 +194,9 @@ class CodeGenTBAA {
190194
/// the given type.
191195
llvm::MDNode *getTBAAStructInfo(QualType QTy);
192196

193-
/// getBaseTypeInfo - Get metadata that describes the given base access type.
194-
/// Return null if the type is not suitable for use in TBAA access tags.
197+
/// getBaseTypeInfo - Get metadata that describes the given base access
198+
/// type. Return null if the type is not suitable for use in TBAA access
199+
/// tags.
195200
llvm::MDNode *getBaseTypeInfo(QualType QTy);
196201

197202
/// getAccessTagInfo - Get TBAA tag for a given memory access.

0 commit comments

Comments
 (0)