aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/DeclBase.cpp
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2024-01-10 21:05:09 -0500
committerNico Weber <thakis@chromium.org>2024-01-10 21:05:19 -0500
commit2dce77201c0c6b541a53aa7a09ec06e7561e8f74 (patch)
tree219e374626cb59cd15f5c0147b3e99b8297516e0 /clang/lib/AST/DeclBase.cpp
parentd85a13b867b17fa93965bc7e439a58c954045217 (diff)
downloadllvm-2dce77201c0c6b541a53aa7a09ec06e7561e8f74.zip
llvm-2dce77201c0c6b541a53aa7a09ec06e7561e8f74.tar.gz
llvm-2dce77201c0c6b541a53aa7a09ec06e7561e8f74.tar.bz2
Revert "[Clang] Implement the 'counted_by' attribute (#76348)"
This reverts commit fefdef808c230c79dca2eb504490ad0f17a765a5. Breaks check-clang, see https://github.com/llvm/llvm-project/pull/76348#issuecomment-1886029515 Also revert follow-on "[Clang] Update 'counted_by' documentation" This reverts commit 4a3fb9ce27dda17e97341f28005a28836c909cfc.
Diffstat (limited to 'clang/lib/AST/DeclBase.cpp')
-rw-r--r--clang/lib/AST/DeclBase.cpp74
1 files changed, 1 insertions, 73 deletions
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 8163f9b..b1733c2 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -29,6 +29,7 @@
#include "clang/AST/Type.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangOptions.h"
#include "clang/Basic/Module.h"
#include "clang/Basic/ObjCRuntime.h"
#include "clang/Basic/PartialDiagnostic.h"
@@ -410,79 +411,6 @@ bool Decl::isFileContextDecl() const {
return DC && DC->isFileContext();
}
-bool Decl::isFlexibleArrayMemberLike(
- ASTContext &Ctx, const Decl *D, QualType Ty,
- LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel,
- bool IgnoreTemplateOrMacroSubstitution) {
- // For compatibility with existing code, we treat arrays of length 0 or
- // 1 as flexible array members.
- const auto *CAT = Ctx.getAsConstantArrayType(Ty);
- if (CAT) {
- using FAMKind = LangOptions::StrictFlexArraysLevelKind;
-
- llvm::APInt Size = CAT->getSize();
- if (StrictFlexArraysLevel == FAMKind::IncompleteOnly)
- return false;
-
- // GCC extension, only allowed to represent a FAM.
- if (Size.isZero())
- return true;
-
- if (StrictFlexArraysLevel == FAMKind::ZeroOrIncomplete && Size.uge(1))
- return false;
-
- if (StrictFlexArraysLevel == FAMKind::OneZeroOrIncomplete && Size.uge(2))
- return false;
- } else if (!Ctx.getAsIncompleteArrayType(Ty)) {
- return false;
- }
-
- if (const auto *OID = dyn_cast_if_present<ObjCIvarDecl>(D))
- return OID->getNextIvar() == nullptr;
-
- const auto *FD = dyn_cast_if_present<FieldDecl>(D);
- if (!FD)
- return false;
-
- if (CAT) {
- // GCC treats an array memeber of a union as an FAM if the size is one or
- // zero.
- llvm::APInt Size = CAT->getSize();
- if (FD->getParent()->isUnion() && (Size.isZero() || Size.isOne()))
- return true;
- }
-
- // Don't consider sizes resulting from macro expansions or template argument
- // substitution to form C89 tail-padded arrays.
- if (IgnoreTemplateOrMacroSubstitution) {
- TypeSourceInfo *TInfo = FD->getTypeSourceInfo();
- while (TInfo) {
- TypeLoc TL = TInfo->getTypeLoc();
-
- // Look through typedefs.
- if (TypedefTypeLoc TTL = TL.getAsAdjusted<TypedefTypeLoc>()) {
- const TypedefNameDecl *TDL = TTL.getTypedefNameDecl();
- TInfo = TDL->getTypeSourceInfo();
- continue;
- }
-
- if (auto CTL = TL.getAs<ConstantArrayTypeLoc>()) {
- if (const Expr *SizeExpr =
- dyn_cast_if_present<IntegerLiteral>(CTL.getSizeExpr());
- !SizeExpr || SizeExpr->getExprLoc().isMacroID())
- return false;
- }
-
- break;
- }
- }
-
- // Test that the field is the last in the structure.
- RecordDecl::field_iterator FI(
- DeclContext::decl_iterator(const_cast<FieldDecl *>(FD)));
- return ++FI == FD->getParent()->field_end();
-}
-
TranslationUnitDecl *Decl::getTranslationUnitDecl() {
if (auto *TUD = dyn_cast<TranslationUnitDecl>(this))
return TUD;