Skip to content

Commit 77d6984

Browse files
committed
Merge remote-tracking branch 'origin/main' into aballman-c23-attr-equivalence
2 parents cf6982b + d2361e4 commit 77d6984

File tree

205 files changed

+9717
-1695
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

205 files changed

+9717
-1695
lines changed

clang/include/clang/Basic/DiagnosticASTKinds.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,14 @@ def note_odr_number_of_bases : Note<
511511
"class has %0 base %plural{1:class|:classes}0">;
512512
def note_odr_enumerator : Note<"enumerator %0 with value %1 here">;
513513
def note_odr_missing_enumerator : Note<"no corresponding enumerator here">;
514+
def note_odr_incompatible_fixed_underlying_type : Note<
515+
"enumeration %0 declared with incompatible fixed underlying types (%1 vs. "
516+
"%2)">;
517+
def note_odr_fixed_underlying_type : Note<
518+
"enumeration %0 has fixed underlying type here">;
519+
def note_odr_missing_fixed_underlying_type : Note<
520+
"enumeration %0 missing fixed underlying type here">;
521+
514522
def err_odr_field_type_inconsistent : Error<
515523
"field %0 declared with incompatible types in different "
516524
"translation units (%1 vs. %2)">;

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
7575
return getConstant(loc, cir::IntAttr::get(ty, value));
7676
}
7777

78+
mlir::Value getSignedInt(mlir::Location loc, int64_t val, unsigned numBits) {
79+
auto type = cir::IntType::get(getContext(), numBits, /*isSigned=*/true);
80+
return getConstAPInt(loc, type,
81+
llvm::APInt(numBits, val, /*isSigned=*/true));
82+
}
83+
7884
mlir::Value getUnsignedInt(mlir::Location loc, uint64_t val,
7985
unsigned numBits) {
8086
auto type = cir::IntType::get(getContext(), numBits, /*isSigned=*/false);

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,8 @@ def CIR_ConditionOp : CIR_Op<"condition", [
607607
//===----------------------------------------------------------------------===//
608608

609609
defvar CIR_YieldableScopes = [
610-
"ArrayCtor", "CaseOp", "DoWhileOp", "ForOp", "IfOp", "ScopeOp", "SwitchOp",
611-
"TernaryOp", "WhileOp"
610+
"ArrayCtor", "ArrayDtor", "CaseOp", "DoWhileOp", "ForOp", "IfOp", "ScopeOp",
611+
"SwitchOp", "TernaryOp", "WhileOp"
612612
];
613613

614614
def CIR_YieldOp : CIR_Op<"yield", [
@@ -1946,6 +1946,10 @@ def CIR_FuncOp : CIR_Op<"func", [
19461946
The function linkage information is specified by `linkage`, as defined by
19471947
`GlobalLinkageKind` attribute.
19481948

1949+
The `no_proto` keyword is used to identify functions that were declared
1950+
without a prototype and, consequently, may contain calls with invalid
1951+
arguments and undefined behavior.
1952+
19491953
Example:
19501954

19511955
```mlir
@@ -1964,6 +1968,7 @@ def CIR_FuncOp : CIR_Op<"func", [
19641968
let arguments = (ins SymbolNameAttr:$sym_name,
19651969
CIR_VisibilityAttr:$global_visibility,
19661970
TypeAttrOf<CIR_FuncType>:$function_type,
1971+
UnitAttr:$no_proto,
19671972
UnitAttr:$dso_local,
19681973
DefaultValuedAttr<CIR_GlobalLinkageKind,
19691974
"cir::GlobalLinkageKind::ExternalLinkage">:$linkage,
@@ -2005,13 +2010,6 @@ def CIR_FuncOp : CIR_Op<"func", [
20052010
return getFunctionType().getReturnTypes();
20062011
}
20072012

2008-
// TODO(cir): this should be an operand attribute, but for now we just hard-
2009-
// wire this as a function. Will later add a $no_proto argument to this op.
2010-
bool getNoProto() {
2011-
assert(!cir::MissingFeatures::opFuncNoProto());
2012-
return false;
2013-
}
2014-
20152013
//===------------------------------------------------------------------===//
20162014
// SymbolOpInterface Methods
20172015
//===------------------------------------------------------------------===//
@@ -2229,7 +2227,7 @@ def CIR_TrapOp : CIR_Op<"trap", [Terminator]> {
22292227
}
22302228

22312229
//===----------------------------------------------------------------------===//
2232-
// ArrayCtor
2230+
// ArrayCtor & ArrayDtor
22332231
//===----------------------------------------------------------------------===//
22342232

22352233
class CIR_ArrayInitDestroy<string mnemonic> : CIR_Op<mnemonic> {
@@ -2260,7 +2258,9 @@ def CIR_ArrayCtor : CIR_ArrayInitDestroy<"array.ctor"> {
22602258
let description = [{
22612259
Initialize each array element using the same C++ constructor. This
22622260
operation has one region, with one single block. The block has an
2263-
incoming argument for the current array index to initialize.
2261+
incoming argument for the current array element to initialize.
2262+
2263+
Example:
22642264

22652265
```mlir
22662266
cir.array.ctor(%0 : !cir.ptr<!cir.array<!rec_S x 42>>) {
@@ -2272,6 +2272,25 @@ def CIR_ArrayCtor : CIR_ArrayInitDestroy<"array.ctor"> {
22722272
}];
22732273
}
22742274

2275+
def CIR_ArrayDtor : CIR_ArrayInitDestroy<"array.dtor"> {
2276+
let summary = "Destroy array elements with C++ dtors";
2277+
let description = [{
2278+
Destroy each array element using the same C++ destructor. This
2279+
operation has one region, with one single block. The block has an
2280+
incoming argument for the current array element to destruct.
2281+
2282+
Example:
2283+
2284+
```mlir
2285+
cir.array.dtor(%0 : !cir.ptr<!cir.array<!rec_S x 42>>) {
2286+
^bb0(%arg0: !cir.ptr<!rec_S>):
2287+
cir.call @some_dtor(%arg0) : (!cir.ptr<!rec_S>) -> ()
2288+
cir.yield
2289+
}
2290+
```
2291+
}];
2292+
}
2293+
22752294
//===----------------------------------------------------------------------===//
22762295
// VecCreate
22772296
//===----------------------------------------------------------------------===//

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,16 @@ struct MissingFeatures {
7373
// FuncOp handling
7474
static bool opFuncOpenCLKernelMetadata() { return false; }
7575
static bool opFuncAstDeclAttr() { return false; }
76+
static bool opFuncAttributesForDefinition() { return false; }
7677
static bool opFuncCallingConv() { return false; }
77-
static bool opFuncExtraAttrs() { return false; }
78-
static bool opFuncNoProto() { return false; }
7978
static bool opFuncCPUAndFeaturesAttributes() { return false; }
80-
static bool opFuncSection() { return false; }
81-
static bool opFuncMultipleReturnVals() { return false; }
82-
static bool opFuncAttributesForDefinition() { return false; }
79+
static bool opFuncExceptions() { return false; }
80+
static bool opFuncExtraAttrs() { return false; }
8381
static bool opFuncMaybeHandleStaticInExternC() { return false; }
82+
static bool opFuncMultipleReturnVals() { return false; }
83+
static bool opFuncOperandBundles() { return false; }
84+
static bool opFuncParameterAttributes() { return false; }
85+
static bool opFuncSection() { return false; }
8486
static bool setLLVMFunctionFEnvAttributes() { return false; }
8587
static bool setFunctionAttributes() { return false; }
8688

@@ -96,7 +98,6 @@ struct MissingFeatures {
9698
static bool opCallReturn() { return false; }
9799
static bool opCallArgEvaluationOrder() { return false; }
98100
static bool opCallCallConv() { return false; }
99-
static bool opCallNoPrototypeFunc() { return false; }
100101
static bool opCallMustTail() { return false; }
101102
static bool opCallVirtual() { return false; }
102103
static bool opCallInAlloca() { return false; }
@@ -109,6 +110,7 @@ struct MissingFeatures {
109110
static bool opCallCIRGenFuncInfoExtParamInfo() { return false; }
110111
static bool opCallLandingPad() { return false; }
111112
static bool opCallContinueBlock() { return false; }
113+
static bool opCallChain() { return false; }
112114

113115
// CXXNewExpr
114116
static bool exprNewNullCheck() { return false; }

clang/lib/AST/ASTStructuralEquivalence.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,6 +2095,48 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
20952095
!CheckStructurallyEquivalentAttributes(Context, D1, D2))
20962096
return false;
20972097

2098+
// In C23, if one enumeration has a fixed underlying type, the other shall
2099+
// have a compatible fixed underlying type (6.2.7).
2100+
if (Context.LangOpts.C23) {
2101+
if (D1->isFixed() != D2->isFixed()) {
2102+
if (Context.Complain) {
2103+
Context.Diag2(D2->getLocation(),
2104+
Context.getApplicableDiagnostic(
2105+
diag::err_odr_tag_type_inconsistent))
2106+
<< Context.ToCtx.getTypeDeclType(D2)
2107+
<< (&Context.FromCtx != &Context.ToCtx);
2108+
Context.Diag1(D1->getLocation(),
2109+
D1->isFixed()
2110+
? diag::note_odr_fixed_underlying_type
2111+
: diag::note_odr_missing_fixed_underlying_type)
2112+
<< D1;
2113+
Context.Diag2(D2->getLocation(),
2114+
D2->isFixed()
2115+
? diag::note_odr_fixed_underlying_type
2116+
: diag::note_odr_missing_fixed_underlying_type)
2117+
<< D2;
2118+
}
2119+
return false;
2120+
}
2121+
if (D1->isFixed()) {
2122+
assert(D2->isFixed() && "enums expected to have fixed underlying types");
2123+
if (!IsStructurallyEquivalent(Context, D1->getIntegerType(),
2124+
D2->getIntegerType())) {
2125+
if (Context.Complain) {
2126+
Context.Diag2(D2->getLocation(),
2127+
Context.getApplicableDiagnostic(
2128+
diag::err_odr_tag_type_inconsistent))
2129+
<< Context.ToCtx.getTypeDeclType(D2)
2130+
<< (&Context.FromCtx != &Context.ToCtx);
2131+
Context.Diag2(D2->getLocation(),
2132+
diag::note_odr_incompatible_fixed_underlying_type)
2133+
<< D2 << D2->getIntegerType() << D1->getIntegerType();
2134+
}
2135+
return false;
2136+
}
2137+
}
2138+
}
2139+
20982140
llvm::SmallVector<const EnumConstantDecl *, 8> D1Enums, D2Enums;
20992141
auto CopyEnumerators =
21002142
[](auto &&Range, llvm::SmallVectorImpl<const EnumConstantDecl *> &Cont) {

clang/lib/AST/ByteCode/Interp.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -481,13 +481,11 @@ inline bool Mulc(InterpState &S, CodePtr OpPC) {
481481
Floating RA = S.allocFloat(A.getSemantics());
482482
RA.copy(ResR);
483483
Result.elem<Floating>(0) = RA; // Floating(ResR);
484-
Result.atIndex(0).initialize();
485484

486485
Floating RI = S.allocFloat(A.getSemantics());
487486
RI.copy(ResI);
488487
Result.elem<Floating>(1) = RI; // Floating(ResI);
489-
Result.atIndex(1).initialize();
490-
Result.initialize();
488+
Result.initializeAllElements();
491489
} else {
492490
// Integer element type.
493491
const T &LHSR = LHS.elem<T>(0);
@@ -505,7 +503,6 @@ inline bool Mulc(InterpState &S, CodePtr OpPC) {
505503
return false;
506504
if (T::sub(A, B, Bits, &Result.elem<T>(0)))
507505
return false;
508-
Result.atIndex(0).initialize();
509506

510507
// imag(Result) = (real(LHS) * imag(RHS)) + (imag(LHS) * real(RHS))
511508
if (T::mul(LHSR, RHSI, Bits, &A))
@@ -514,8 +511,8 @@ inline bool Mulc(InterpState &S, CodePtr OpPC) {
514511
return false;
515512
if (T::add(A, B, Bits, &Result.elem<T>(1)))
516513
return false;
517-
Result.atIndex(1).initialize();
518514
Result.initialize();
515+
Result.initializeAllElements();
519516
}
520517

521518
return true;
@@ -541,14 +538,12 @@ inline bool Divc(InterpState &S, CodePtr OpPC) {
541538
Floating RA = S.allocFloat(A.getSemantics());
542539
RA.copy(ResR);
543540
Result.elem<Floating>(0) = RA; // Floating(ResR);
544-
Result.atIndex(0).initialize();
545541

546542
Floating RI = S.allocFloat(A.getSemantics());
547543
RI.copy(ResI);
548544
Result.elem<Floating>(1) = RI; // Floating(ResI);
549-
Result.atIndex(1).initialize();
550545

551-
Result.initialize();
546+
Result.initializeAllElements();
552547
} else {
553548
// Integer element type.
554549
const T &LHSR = LHS.elem<T>(0);
@@ -590,7 +585,6 @@ inline bool Divc(InterpState &S, CodePtr OpPC) {
590585
return false;
591586
if (T::div(ResultR, Den, Bits, &ResultR))
592587
return false;
593-
Result.atIndex(0).initialize();
594588

595589
// imag(Result) = ((imag(LHS) * real(RHS)) - (real(LHS) * imag(RHS))) / Den
596590
if (T::mul(LHSI, RHSR, Bits, &A) || T::mul(LHSR, RHSI, Bits, &B))
@@ -599,8 +593,7 @@ inline bool Divc(InterpState &S, CodePtr OpPC) {
599593
return false;
600594
if (T::div(ResultI, Den, Bits, &ResultI))
601595
return false;
602-
Result.atIndex(1).initialize();
603-
Result.initialize();
596+
Result.initializeAllElements();
604597
}
605598

606599
return true;

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,10 +1099,8 @@ static bool interp__builtin_complex(InterpState &S, CodePtr OpPC,
10991099
Pointer &Result = S.Stk.peek<Pointer>();
11001100

11011101
Result.elem<Floating>(0) = Arg1;
1102-
Result.atIndex(0).initialize();
11031102
Result.elem<Floating>(1) = Arg2;
1104-
Result.atIndex(1).initialize();
1105-
Result.initialize();
1103+
Result.initializeAllElements();
11061104

11071105
return true;
11081106
}
@@ -1728,9 +1726,9 @@ static bool interp__builtin_elementwise_popcount(InterpState &S, CodePtr OpPC,
17281726
Dst.elem<T>(I) =
17291727
T::from(Arg.elem<T>(I).toAPSInt().reverseBits().getZExtValue());
17301728
}
1731-
Dst.atIndex(I).initialize();
17321729
});
17331730
}
1731+
Dst.initializeAllElements();
17341732

17351733
return true;
17361734
}
@@ -2314,12 +2312,10 @@ static bool interp__builtin_elementwise_sat(InterpState &S, CodePtr OpPC,
23142312
llvm_unreachable("Wrong builtin ID");
23152313
}
23162314

2317-
INT_TYPE_SWITCH_NO_BOOL(ElemT, {
2318-
const Pointer &E = Dst.atIndex(I);
2319-
E.deref<T>() = static_cast<T>(Result);
2320-
E.initialize();
2321-
});
2315+
INT_TYPE_SWITCH_NO_BOOL(ElemT,
2316+
{ Dst.elem<T>(I) = static_cast<T>(Result); });
23222317
}
2318+
Dst.initializeAllElements();
23232319

23242320
return true;
23252321
}

clang/lib/AST/ByteCode/Pointer.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,19 @@ void Pointer::initialize() const {
495495
getInlineDesc()->IsInitialized = true;
496496
}
497497

498+
void Pointer::initializeAllElements() const {
499+
assert(getFieldDesc()->isPrimitiveArray());
500+
assert(isArrayRoot());
501+
502+
InitMapPtr &IM = getInitMap();
503+
if (!IM) {
504+
IM = std::make_pair(true, nullptr);
505+
} else {
506+
IM->first = true;
507+
IM->second.reset();
508+
}
509+
}
510+
498511
void Pointer::activate() const {
499512
// Field has its bit in an inline descriptor.
500513
assert(PointeeStorage.BS.Base != 0 &&

clang/lib/AST/ByteCode/Pointer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,10 @@ class Pointer {
725725

726726
/// Initializes a field.
727727
void initialize() const;
728+
/// Initialize all elements of a primitive array at once. This can be
729+
/// used in situations where we *know* we have initialized *all* elements
730+
/// of a primtive array.
731+
void initializeAllElements() const;
728732
/// Activats a field.
729733
void activate() const;
730734
/// Deactivates an entire strurcutre.

clang/lib/AST/RecordLayoutBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1953,7 +1953,7 @@ void ItaniumRecordLayoutBuilder::LayoutField(const FieldDecl *D,
19531953
// silently there. For other targets that have ms_struct enabled
19541954
// (most probably via a pragma or attribute), trigger a diagnostic
19551955
// that defaults to an error.
1956-
if (!Context.getTargetInfo().getTriple().isWindowsGNUEnvironment())
1956+
if (!Context.getTargetInfo().getTriple().isOSCygMing())
19571957
Diag(D->getLocation(), diag::warn_npot_ms_struct);
19581958
}
19591959
if (TypeSize > FieldAlign &&

0 commit comments

Comments
 (0)