Skip to content

Commit f14862f

Browse files
authored
Merge branch 'main' into users/xlauko/cir-opt-test-verify-roundtrip
2 parents e1daf4b + 78c6554 commit f14862f

File tree

349 files changed

+4917
-12790
lines changed

Some content is hidden

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

349 files changed

+4917
-12790
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ Non-comprehensive list of changes in this release
246246

247247
- ``__builtin_assume_dereferenceable`` now accepts non-constant size operands.
248248

249+
- Fixed a crash when the second argument to ``__builtin_assume_aligned`` was not constant (#GH161314)
250+
249251
New Compiler Flags
250252
------------------
251253
- New option ``-fno-sanitize-debug-trap-reasons`` added to disable emitting trap reasons into the debug info when compiling with trapping UBSan (e.g. ``-fsanitize-trap=undefined``).

clang/include/clang/AST/CharUnits.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ namespace clang {
141141
/// Among other things, this promises that
142142
/// self.alignTo(N) will just return self.
143143
bool isMultipleOf(CharUnits N) const {
144-
return (*this % N) == 0;
144+
return (*this % N) == CharUnits::Zero();
145145
}
146146

147147
// Arithmetic operators.
@@ -165,8 +165,8 @@ namespace clang {
165165
CharUnits operator% (QuantityType N) const {
166166
return CharUnits(Quantity % N);
167167
}
168-
QuantityType operator% (const CharUnits &Other) const {
169-
return Quantity % Other.Quantity;
168+
CharUnits operator%(const CharUnits &Other) const {
169+
return CharUnits(Quantity % Other.Quantity);
170170
}
171171
CharUnits operator+ (const CharUnits &Other) const {
172172
return CharUnits(Quantity + Other.Quantity);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,10 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
148148
}
149149

150150
mlir::Value createComplexReal(mlir::Location loc, mlir::Value operand) {
151-
auto operandTy = mlir::cast<cir::ComplexType>(operand.getType());
152-
return cir::ComplexRealOp::create(*this, loc, operandTy.getElementType(),
153-
operand);
151+
auto resultType = operand.getType();
152+
if (auto complexResultType = mlir::dyn_cast<cir::ComplexType>(resultType))
153+
resultType = complexResultType.getElementType();
154+
return cir::ComplexRealOp::create(*this, loc, resultType, operand);
154155
}
155156

156157
mlir::Value createComplexImag(mlir::Location loc, mlir::Value operand) {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3260,18 +3260,20 @@ def CIR_ComplexCreateOp : CIR_Op<"complex.create", [Pure, SameTypeOperands]> {
32603260
def CIR_ComplexRealOp : CIR_Op<"complex.real", [Pure]> {
32613261
let summary = "Extract the real part of a complex value";
32623262
let description = [{
3263-
`cir.complex.real` operation takes an operand of `!cir.complex` type and
3264-
yields the real part of it.
3263+
`cir.complex.real` operation takes an operand of `!cir.complex`, `!cir.int`
3264+
or `!cir.float`. If the operand is `!cir.complex`, the real part of it will
3265+
be returned, otherwise the value returned unmodified.
32653266

32663267
Example:
32673268

32683269
```mlir
3269-
%1 = cir.complex.real %0 : !cir.complex<!cir.float> -> !cir.float
3270+
%real = cir.complex.real %complex : !cir.complex<!cir.float> -> !cir.float
3271+
%real = cir.complex.real %scalar : !cir.float -> !cir.float
32703272
```
32713273
}];
32723274

32733275
let results = (outs CIR_AnyIntOrFloatType:$result);
3274-
let arguments = (ins CIR_ComplexType:$operand);
3276+
let arguments = (ins CIR_AnyComplexOrIntOrFloatType:$operand);
32753277

32763278
let assemblyFormat = [{
32773279
$operand `:` qualified(type($operand)) `->` qualified(type($result))

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ def CIR_AnyIntOrFloatType : AnyTypeOf<[CIR_AnyFloatType, CIR_AnyIntType],
165165

166166
def CIR_AnyComplexType : CIR_TypeBase<"::cir::ComplexType", "complex type">;
167167

168+
def CIR_AnyComplexOrIntOrFloatType : AnyTypeOf<[
169+
CIR_AnyComplexType, CIR_AnyFloatType, CIR_AnyIntType
170+
], "complex, integer or floating point type"> {
171+
let cppFunctionName = "isComplexOrIntegerOrFloatingPointType";
172+
}
173+
168174
//===----------------------------------------------------------------------===//
169175
// Array Type predicates
170176
//===----------------------------------------------------------------------===//

clang/lib/AST/APValue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ void APValue::printPretty(raw_ostream &Out, const PrintingPolicy &Policy,
784784
if (!O.isZero()) {
785785
if (IsReference)
786786
Out << "*(";
787-
if (S.isZero() || O % S) {
787+
if (S.isZero() || !O.isMultipleOf(S)) {
788788
Out << "(char*)";
789789
S = CharUnits::One();
790790
}

clang/lib/AST/RecordLayoutBuilder.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,9 +2087,8 @@ void ItaniumRecordLayoutBuilder::LayoutField(const FieldDecl *D,
20872087
if (InsertExtraPadding) {
20882088
CharUnits ASanAlignment = CharUnits::fromQuantity(8);
20892089
CharUnits ExtraSizeForAsan = ASanAlignment;
2090-
if (FieldSize % ASanAlignment)
2091-
ExtraSizeForAsan +=
2092-
ASanAlignment - CharUnits::fromQuantity(FieldSize % ASanAlignment);
2090+
if (!FieldSize.isMultipleOf(ASanAlignment))
2091+
ExtraSizeForAsan += ASanAlignment - (FieldSize % ASanAlignment);
20932092
EffectiveFieldSize = FieldSize = FieldSize + ExtraSizeForAsan;
20942093
}
20952094

@@ -2119,10 +2118,10 @@ void ItaniumRecordLayoutBuilder::LayoutField(const FieldDecl *D,
21192118
if (RD->hasAttr<PackedAttr>() || !MaxFieldAlignment.isZero())
21202119
if (FieldAlign < OriginalFieldAlign)
21212120
if (D->getType()->isRecordType()) {
2122-
// If the offset is a multiple of the alignment of
2121+
// If the offset is not a multiple of the alignment of
21232122
// the type, raise the warning.
21242123
// TODO: Takes no account the alignment of the outer struct
2125-
if (FieldOffset % OriginalFieldAlign != 0)
2124+
if (!FieldOffset.isMultipleOf(OriginalFieldAlign))
21262125
Diag(D->getLocation(), diag::warn_unaligned_access)
21272126
<< Context.getCanonicalTagType(RD) << D->getName()
21282127
<< D->getType();

clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
133133
}
134134
void VisitParenExpr(ParenExpr *pe) { Visit(pe->getSubExpr()); }
135135
void VisitGenericSelectionExpr(GenericSelectionExpr *ge) {
136-
cgf.cgm.errorNYI(ge->getSourceRange(),
137-
"AggExprEmitter: VisitGenericSelectionExpr");
136+
Visit(ge->getResultExpr());
138137
}
139138
void VisitCoawaitExpr(CoawaitExpr *e) {
140139
cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitCoawaitExpr");

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,8 +2151,10 @@ mlir::Value ScalarExprEmitter::VisitRealImag(const UnaryOperator *e,
21512151
}
21522152

21532153
if (e->getOpcode() == UO_Real) {
2154-
return promotionTy.isNull() ? Visit(op)
2155-
: cgf.emitPromotedScalarExpr(op, promotionTy);
2154+
mlir::Value operand = promotionTy.isNull()
2155+
? Visit(op)
2156+
: cgf.emitPromotedScalarExpr(op, promotionTy);
2157+
return builder.createComplexReal(loc, operand);
21562158
}
21572159

21582160
// __imag on a scalar returns zero. Emit the subexpr to ensure side

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,8 @@ LValue CIRGenFunction::emitLValue(const Expr *e) {
836836
return emitCallExprLValue(cast<CallExpr>(e));
837837
case Expr::ParenExprClass:
838838
return emitLValue(cast<ParenExpr>(e)->getSubExpr());
839+
case Expr::GenericSelectionExprClass:
840+
return emitLValue(cast<GenericSelectionExpr>(e)->getResultExpr());
839841
case Expr::DeclRefExprClass:
840842
return emitDeclRefLValue(cast<DeclRefExpr>(e));
841843
case Expr::CStyleCastExprClass:

0 commit comments

Comments
 (0)