Skip to content

Commit

Permalink
Fix lint errors (#47)
Browse files Browse the repository at this point in the history
* Fix line errors:

* Fix segfault when run from CLion
* Fix false positive on template dependent type conversions
  • Loading branch information
finomen authored Oct 3, 2022
1 parent 5838797 commit 03e7682
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
12 changes: 8 additions & 4 deletions clang-tools-extra/clang-tidy/daedalean/IncludeOrderCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,15 @@ void IncludeOrderPPCallbacks::InclusionDirective(
LLVM_DEBUG(llvm::dbgs() << "Invalid extension\n");
}

const auto FileEntry = SM.getFileEntryForID(SM.getFileID(HashLoc));

if (!FileEntry) {
// This is not regular file
return;
}

const std::string CurrentDir =
SM.getFileManager()
.getCanonicalName(
SM.getFileEntryForID(SM.getFileID(HashLoc))->getDir())
.str();
SM.getFileManager().getCanonicalName(FileEntry->getDir()).str();
LLVM_DEBUG(llvm::dbgs() << "\tpwd:\t" << CurrentDir << "\n");

const std::string IncludeDir =
Expand Down
48 changes: 25 additions & 23 deletions clang-tools-extra/clang-tidy/daedalean/TypeConversionsCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,72 +207,74 @@ void TypeConversionsCheck::handleImplicitCast(clang::ASTContext *context,
QualType sourceType,
QualType destType,
SourceLocation location) {
if (destType.getCanonicalType() == sourceType.getCanonicalType()) {
const QualType canonicalSourceType = sourceType.getCanonicalType();
const QualType canonicalDestType = destType.getCanonicalType();
if (canonicalDestType == canonicalSourceType) {
// If source and destination are the same type we can ignore the cast
return;
}

if (onlyAddsQualifiers(sourceType.getUnqualifiedType(),
destType.getUnqualifiedType())) {
if (onlyAddsQualifiers(canonicalSourceType.getUnqualifiedType(),
canonicalDestType.getUnqualifiedType())) {
return;
}

if (sourceType->isNullPtrType() &&
(destType->isPointerType() || destType->isMemberPointerType())) {
if (canonicalSourceType->isNullPtrType() &&
(canonicalDestType->isPointerType() || canonicalDestType->isMemberPointerType())) {
// Casting from nullptr to a pointer type is always allowed
return;
}

if (sourceType->isPointerType() && destType->isVoidPointerType()) {
if (canonicalSourceType->isPointerType() && canonicalDestType->isVoidPointerType()) {
// Casting from pointer to void * is allowed
return;
}

if (llvm::isa<BuiltinType>(sourceType)) {
const BuiltinType *Builtin = llvm::dyn_cast<BuiltinType>(sourceType);
if (llvm::isa<BuiltinType>(canonicalSourceType)) {
const BuiltinType *Builtin = llvm::dyn_cast<BuiltinType>(canonicalSourceType);
if ((Builtin->getKind() == BuiltinType::Kind::BuiltinFn) &&
destType->isFunctionPointerType()) {
canonicalDestType->isFunctionPointerType()) {
return;
}
}

if (sourceType->isDependentType() || destType->isDependentType()) {
if (canonicalSourceType->isDependentType() || canonicalDestType->isDependentType()) {
return;
}

if (!sourceType->hasPointerRepresentation() &&
(sourceType.getUnqualifiedType().getCanonicalType() ==
destType.getUnqualifiedType().getCanonicalType())) {
if (!canonicalSourceType->hasPointerRepresentation() &&
(canonicalSourceType.getUnqualifiedType() ==
canonicalDestType.getUnqualifiedType())) {
// Removing qualifiers by value (not reference or pointer types) is ok
return;
}

if (sourceType->canDecayToPointerType()) {
const QualType decayedType = context->getDecayedType(sourceType);
if (decayedType.getCanonicalType() == destType.getCanonicalType()) {
if (canonicalSourceType->canDecayToPointerType()) {
const QualType decayedType = context->getDecayedType(canonicalSourceType);
if (decayedType.getCanonicalType() == canonicalDestType) {
return;
}
}

if (isSafeIntegralCast(context, sourceType, destType)) {
if (isSafeIntegralCast(context, canonicalSourceType, canonicalDestType)) {
// Integral promotion is allowed
return;
}

// Check conversion from child to parent
const CXXRecordDecl *destRecord = destType->getAsCXXRecordDecl();
const CXXRecordDecl *sourceRecord = sourceType->getAsCXXRecordDecl();
const CXXRecordDecl *destRecord = canonicalDestType->getAsCXXRecordDecl();
const CXXRecordDecl *sourceRecord = canonicalSourceType->getAsCXXRecordDecl();
if (sourceRecord && destRecord && sourceRecord->isDerivedFrom(destRecord)) {
// Cast pointer or reference from child to base MAY be implicit.
return;
}

if (hasPointerRepresentation(sourceType) &&
hasPointerRepresentation(destType)) {
if (hasPointerRepresentation(canonicalSourceType) &&
hasPointerRepresentation(canonicalDestType)) {
const CXXRecordDecl *sourceRecord =
getPointee(sourceType)->getAsCXXRecordDecl();
getPointee(canonicalSourceType)->getAsCXXRecordDecl();
const CXXRecordDecl *destRecord =
getPointee(destType)->getAsCXXRecordDecl();
getPointee(canonicalDestType)->getAsCXXRecordDecl();
if (sourceRecord && destRecord && sourceRecord->isDerivedFrom(destRecord)) {
// Cast pointer or reference from child to base MAY be implicit.
return;
Expand Down

0 comments on commit 03e7682

Please sign in to comment.