Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compiling LLDB #24

Open
wants to merge 2 commits into
base: p2996
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
277 changes: 277 additions & 0 deletions P2996.md

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Clang/P2996: An LLVM fork

Welcome to Clang/P2996, a fork of the [`llvm/llvm-project`](
https://github.com/llvm/llvm-project) implementing experimental support for ISO
C++ proposal [P2996](https://wg21.link/p2996) in `clang`. Please see [P2996.md](
P2996.md) for more about this project.

# The LLVM Compiler Infrastructure

[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/llvm/llvm-project/badge)](https://securityscorecards.dev/viewer/?uri=github.com/llvm/llvm-project)
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang-c/Index.h
Original file line number Diff line number Diff line change
Expand Up @@ -3109,6 +3109,7 @@ enum CXTemplateArgumentKind {
CXTemplateArgumentKind_Declaration,
CXTemplateArgumentKind_NullPtr,
CXTemplateArgumentKind_Integral,
CXTemplateArgumentKind_Reflection,
CXTemplateArgumentKind_Template,
CXTemplateArgumentKind_TemplateExpansion,
CXTemplateArgumentKind_Expression,
Expand Down
40 changes: 37 additions & 3 deletions clang/include/clang/AST/APValue.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//===--- APValue.h - Union class for APFloat/APSInt/Complex -----*- C++ -*-===//
//
// Copyright 2024 Bloomberg Finance L.P.
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Expand All @@ -13,6 +15,7 @@
#ifndef LLVM_CLANG_AST_APVALUE_H
#define LLVM_CLANG_AST_APVALUE_H

#include "clang/AST/Reflection.h"
#include "clang/Basic/LLVM.h"
#include "llvm/ADT/APFixedPoint.h"
#include "llvm/ADT/APFloat.h"
Expand All @@ -35,6 +38,7 @@ template <typename T> class BasicReaderBase;
class DiagnosticBuilder;
class Expr;
class FieldDecl;
class NamespaceDecl;
struct PrintingPolicy;
class Type;
class ValueDecl;
Expand Down Expand Up @@ -118,7 +122,7 @@ template<> struct PointerLikeTypeTraits<clang::DynamicAllocLValue> {
namespace clang {
/// APValue - This class implements a discriminated union of [uninitialized]
/// [APSInt] [APFloat], [Complex APSInt] [Complex APFloat], [Expr + Offset],
/// [Vector: N * APValue], [Array: N * APValue]
/// [Vector: N * APValue], [Array: N * APValue], [ReflectionValue]
class APValue {
typedef llvm::APFixedPoint APFixedPoint;
typedef llvm::APSInt APSInt;
Expand All @@ -140,7 +144,8 @@ class APValue {
Struct,
Union,
MemberPointer,
AddrLabelDiff
AddrLabelDiff,
Reflection
};

class LValueBase {
Expand Down Expand Up @@ -308,7 +313,8 @@ class APValue {
// We ensure elsewhere that Data is big enough for LV and MemberPointerData.
typedef llvm::AlignedCharArrayUnion<void *, APSInt, APFloat, ComplexAPSInt,
ComplexAPFloat, Vec, Arr, StructData,
UnionData, AddrLabelDiffData> DataType;
UnionData, AddrLabelDiffData,
ReflectionValue> DataType;
static const size_t DataSize = sizeof(DataType);

DataType Data;
Expand Down Expand Up @@ -363,6 +369,10 @@ class APValue {
: Kind(None) {
MakeAddrLabelDiff(); setAddrLabelDiff(LHSExpr, RHSExpr);
}
APValue(ReflectionValue::ReflectionKind ReflKind, const void *ReflEntity)
: Kind(None) {
MakeReflection(ReflKind, ReflEntity);
}
static APValue IndeterminateValue() {
APValue Result;
Result.Kind = Indeterminate;
Expand Down Expand Up @@ -410,6 +420,7 @@ class APValue {
bool isUnion() const { return Kind == Union; }
bool isMemberPointer() const { return Kind == MemberPointer; }
bool isAddrLabelDiff() const { return Kind == AddrLabelDiff; }
bool isReflection() const { return Kind == Reflection; }

void dump() const;
void dump(raw_ostream &OS, const ASTContext &Context) const;
Expand Down Expand Up @@ -585,6 +596,21 @@ class APValue {
return ((const AddrLabelDiffData *)(const char *)&Data)->RHSExpr;
}

ReflectionValue &getReflection() {
assert(isReflection() && "Invalid accessor");
return *(ReflectionValue *)(char *)&Data;
}
const ReflectionValue &getReflection() const {
return const_cast<APValue*>(this)->getReflection();
}
QualType getReflectedType() const;
ConstantExpr *getReflectedConstValueExpr() const;
ValueDecl *getReflectedDecl() const;
const TemplateName getReflectedTemplate() const;
Decl *getReflectedNamespace() const;
CXXBaseSpecifier *getReflectedBaseSpecifier() const;
TagDataMemberSpec *getReflectedDataMemberSpec() const;

void setInt(APSInt I) {
assert(isInt() && "Invalid accessor");
*(APSInt *)(char *)&Data = std::move(I);
Expand Down Expand Up @@ -679,6 +705,14 @@ class APValue {
new ((void *)(char *)&Data) AddrLabelDiffData();
Kind = AddrLabelDiff;
}
void MakeReflection(ReflectionValue::ReflectionKind ReflKind,
const void *ReflEntity) {
assert(isAbsent() && "Bad state change");

new ((void *)(char *)Data.buffer) ReflectionValue(
ReflKind, const_cast<void *>(ReflEntity));
Kind = Reflection;
}

private:
/// The following functions are used as part of initialization, during
Expand Down
8 changes: 8 additions & 0 deletions clang/include/clang/AST/ASTContext.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//===- ASTContext.h - Context to hold long-lived AST nodes ------*- C++ -*-===//
//
// Copyright 2024 Bloomberg Finance L.P.
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Expand Down Expand Up @@ -235,6 +237,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
ASTContext&>
DependentTemplateSpecializationTypes;
llvm::FoldingSet<PackExpansionType> PackExpansionTypes;
mutable llvm::FoldingSet<DependentReflectionSpliceType>
DependentReflectionSpliceTypes;
mutable llvm::FoldingSet<ObjCObjectTypeImpl> ObjCObjectTypes;
mutable llvm::FoldingSet<ObjCObjectPointerType> ObjCObjectPointerTypes;
mutable llvm::FoldingSet<DependentUnaryTransformType>
Expand Down Expand Up @@ -1116,6 +1120,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
CanQualType BFloat16Ty;
CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3
CanQualType VoidPtrTy, NullPtrTy;
CanQualType MetaInfoTy;
CanQualType DependentTy, OverloadTy, BoundMemberTy, UnknownAnyTy;
CanQualType BuiltinFnTy;
CanQualType PseudoObjectTy, ARCUnbridgedCastTy;
Expand Down Expand Up @@ -1692,6 +1697,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
std::optional<unsigned> NumExpansions,
bool ExpectPackInType = true);

QualType getReflectionSpliceType(Expr *E, QualType UnderlyingType) const;

QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl,
ObjCInterfaceDecl *PrevDecl = nullptr) const;

Expand Down Expand Up @@ -2217,6 +2224,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
const IdentifierInfo *Name) const;
TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
OverloadedOperatorKind Operator) const;
TemplateName getDependentTemplateName(CXXIndeterminateSpliceExpr *S) const;
TemplateName
getSubstTemplateTemplateParm(TemplateName replacement, Decl *AssociatedDecl,
unsigned Index,
Expand Down
11 changes: 11 additions & 0 deletions clang/include/clang/AST/AbstractBasicReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ class DataStreamBasicReader : public BasicReaderBase<Impl> {
return llvm::APInt(bitWidth, numWords, &data[0]);
}

ReflectionValue readReflectionValue() {
llvm_unreachable("unimplemented");
}

llvm::FixedPointSemantics readFixedPointSemantics() {
unsigned width = asImpl().readUInt32();
unsigned scale = asImpl().readUInt32();
Expand Down Expand Up @@ -284,6 +288,13 @@ class DataStreamBasicReader : public BasicReaderBase<Impl> {
cur = NestedNameSpecifier::SuperSpecifier(ctx,
asImpl().readCXXRecordDeclRef());
continue;

case NestedNameSpecifier::IndeterminateSplice:
cur = NestedNameSpecifier::IndeterminateSpliceSpecifier(
ctx,
reinterpret_cast<CXXIndeterminateSpliceExpr *>(
asImpl().readExprRef()));
continue;
}
llvm_unreachable("bad nested name specifier kind");
}
Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/AST/AbstractBasicWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ class DataStreamBasicWriter : public BasicWriterBase<Impl> {
case NestedNameSpecifier::Super:
asImpl().writeDeclRef(NNS->getAsRecordDecl());
continue;

case NestedNameSpecifier::IndeterminateSplice:
asImpl().writeExprRef(NNS->getAsSpliceExpr());
continue;
}
llvm_unreachable("bad nested name specifier kind");
}
Expand Down
6 changes: 6 additions & 0 deletions clang/include/clang/AST/BuiltinTypes.def
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//===-- BuiltinTypes.def - Metadata about BuiltinTypes ----------*- C++ -*-===//
//
// Copyright 2024 Bloomberg Finance L.P.
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Expand Down Expand Up @@ -226,6 +228,10 @@ FLOATING_TYPE(Ibm128, Ibm128Ty)
// This is the type of C++0x 'nullptr'.
BUILTIN_TYPE(NullPtr, NullPtrTy)

// This is this type proposed for C++2c by P2996 for representing
// internal compiler objects reflected by a value.
BUILTIN_TYPE(MetaInfo, MetaInfoTy)

// The primitive Objective C 'id' type. The user-visible 'id'
// type is a typedef of an ObjCObjectPointerType to an
// ObjCObjectType with this as its base. In fact, this only ever
Expand Down
17 changes: 17 additions & 0 deletions clang/include/clang/AST/ComputeDependence.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//===--- ComputeDependence.h -------------------------------------- C++ -*-===//
//
// Copyright 2024 Bloomberg Finance L.P.
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Expand Down Expand Up @@ -94,6 +96,13 @@ class DesignatedInitExpr;
class ParenListExpr;
class PseudoObjectExpr;
class AtomicExpr;
class CXXReflectExpr;
class CXXMetafunctionExpr;
class CXXIndeterminateSpliceExpr;
class CXXExprSpliceExpr;
class CXXDependentMemberSpliceExpr;
class StackLocationExpr;
class ValueOfLValueExpr;
class OMPArraySectionExpr;
class OMPArrayShapingExpr;
class OMPIteratorExpr;
Expand Down Expand Up @@ -189,6 +198,14 @@ ExprDependence computeDependence(ParenListExpr *E);
ExprDependence computeDependence(PseudoObjectExpr *E);
ExprDependence computeDependence(AtomicExpr *E);

ExprDependence computeDependence(CXXReflectExpr *E, const ASTContext &C);
ExprDependence computeDependence(CXXMetafunctionExpr *E);
ExprDependence computeDependence(CXXIndeterminateSpliceExpr *E);
ExprDependence computeDependence(CXXExprSpliceExpr *E);
ExprDependence computeDependence(CXXDependentMemberSpliceExpr *E);
ExprDependence computeDependence(StackLocationExpr *E);
ExprDependence computeDependence(ValueOfLValueExpr *E);

ExprDependence computeDependence(OMPArraySectionExpr *E);
ExprDependence computeDependence(OMPArrayShapingExpr *E);
ExprDependence computeDependence(OMPIteratorExpr *E);
Expand Down
12 changes: 10 additions & 2 deletions clang/include/clang/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,12 @@ class NamespaceDecl : public NamedDecl, public DeclContext,
llvm::PointerIntPair<NamespaceDecl *, 2, unsigned>
AnonOrFirstNamespaceAndFlags;

NamespaceDecl(ASTContext &C, DeclContext *DC, bool Inline,
protected:
NamespaceDecl(Kind K, ASTContext &C, DeclContext *DC, bool Inline,
SourceLocation StartLoc, SourceLocation IdLoc,
IdentifierInfo *Id, NamespaceDecl *PrevDecl, bool Nested);

private:
using redeclarable_base = Redeclarable<NamespaceDecl>;

NamespaceDecl *getNextRedeclarationImpl() override;
Expand Down Expand Up @@ -689,7 +691,9 @@ class NamespaceDecl : public NamedDecl, public DeclContext,

// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classofKind(Kind K) { return K == Namespace; }
static bool classofKind(Kind K) {
return K >= firstNamespace && K <= lastNamespace;
}
static DeclContext *castToDeclContext(const NamespaceDecl *D) {
return static_cast<DeclContext *>(const_cast<NamespaceDecl*>(D));
}
Expand Down Expand Up @@ -4296,6 +4300,10 @@ class RecordDecl : public TagDecl {

void setIsRandomized(bool V) { RecordDeclBits.IsRandomized = V; }

bool isMetaType() const { return RecordDeclBits.IsMetaType; }

void setIsMetaType(bool V) { RecordDeclBits.IsMetaType = V; }

void reorderDecls(const SmallVectorImpl<Decl *> &Decls);

/// Determines whether this declaration represents the
Expand Down
6 changes: 5 additions & 1 deletion clang/include/clang/AST/DeclBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -1668,9 +1668,13 @@ class DeclContext {
LLVM_PREFERRED_TYPE(bool)
uint64_t IsRandomized : 1;

/// Indicates whether this struct is a meta type.
LLVM_PREFERRED_TYPE(bool)
uint64_t IsMetaType : 1;

/// True if a valid hash is stored in ODRHash. This should shave off some
/// extra storage and prevent CXXRecordDecl to store unused bits.
uint64_t ODRHash : 26;
uint64_t ODRHash : 25;
};

/// Number of inherited and non-inherited bits in RecordDeclBitfields.
Expand Down
Loading