Skip to content

Commit 266ff53

Browse files
authored
Merge branch 'users/kparzysz/spr/d01-name-parser' into users/kparzysz/spr/d02-clang-parser
2 parents ab3f0cc + 2768326 commit 266ff53

File tree

434 files changed

+50106
-47105
lines changed

Some content is hidden

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

434 files changed

+50106
-47105
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,9 @@ Improvements to Clang's diagnostics
661661
diagnostics when floating-point numbers had both width field and plus or space
662662
prefix specified. (#GH143951)
663663

664+
- A warning is now emitted when ``main`` is attached to a named module,
665+
which can be turned off with ``-Wno-main-attached-to-named-module``. (#GH146247)
666+
664667
- Clang now avoids issuing `-Wreturn-type` warnings in some cases where
665668
the final statement of a non-void function is a `throw` expression, or
666669
a call to a function that is trivially known to always throw (i.e., its

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,9 @@ def err_constexpr_main : Error<
10621062
"'main' is not allowed to be declared %select{constexpr|consteval}0">;
10631063
def err_deleted_main : Error<"'main' is not allowed to be deleted">;
10641064
def err_mainlike_template_decl : Error<"%0 cannot be a template">;
1065+
def warn_main_in_named_module
1066+
: ExtWarn<"'main' never has module linkage">,
1067+
InGroup<DiagGroup<"main-attached-to-named-module">>;
10651068
def err_main_returns_nonint : Error<"'main' must return 'int'">;
10661069
def ext_main_returns_nonint : ExtWarn<"return type of 'main' is not 'int'">,
10671070
InGroup<MainReturnType>;
@@ -13214,8 +13217,12 @@ def err_acc_not_a_var_ref_use_device_declare
1321413217
: Error<"OpenACC variable %select{in 'use_device' clause|on 'declare' "
1321513218
"construct}0 is not a valid variable name or array name">;
1321613219
def err_acc_not_a_var_ref_cache
13217-
: Error<"OpenACC variable in cache directive is not a valid sub-array or "
13220+
: Error<"OpenACC variable in 'cache' directive is not a valid sub-array or "
1321813221
"array element">;
13222+
def warn_acc_cache_var_not_outside_loop
13223+
: Warning<"OpenACC variable in 'cache' directive was not declared outside "
13224+
"of the associated 'loop' directive; directive has no effect">,
13225+
InGroup<DiagGroup<"openacc-cache-var-inside-loop">>;
1321913226
def err_acc_typecheck_subarray_value
1322013227
: Error<"OpenACC sub-array subscripted value is not an array or pointer">;
1322113228
def err_acc_subarray_function_type

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,4 +453,67 @@ def CIR_VisibilityAttr : CIR_EnumAttr<CIR_VisibilityKind, "visibility"> {
453453
}];
454454
}
455455

456+
//===----------------------------------------------------------------------===//
457+
// BitfieldInfoAttr
458+
//===----------------------------------------------------------------------===//
459+
460+
def BitfieldInfoAttr : CIR_Attr<"BitfieldInfo", "bitfield_info"> {
461+
let summary = "Represents info for a bit-field member";
462+
let description = [{
463+
Holds the following information about bitfields: name, storage type, size
464+
and position in the storage, and signedness.
465+
Example:
466+
Given the following struct with bitfields:
467+
```c++
468+
typedef struct {
469+
int a : 4;
470+
int b : 27;
471+
int c : 17;
472+
int d : 2;
473+
int e : 15;
474+
} S;
475+
```
476+
477+
The CIR representation of the struct `S` might look like:
478+
```mlir
479+
!rec_S = !cir.record<struct "S" packed padded {!u64i, !u16i,
480+
!cir.array<!u8i x 2>}>
481+
```
482+
And the bitfield info attribute for member `a` would be:
483+
```mlir
484+
#bfi_a = #cir.bitfield_info<name = "a", storage_type = !u64i,
485+
size = 4, offset = 0, is_signed = true>
486+
```
487+
488+
This metadata describes that field `a` is stored in a 64-bit integer,
489+
is 4 bits wide, starts at offset 0, and is signed.
490+
}];
491+
let parameters = (ins "mlir::StringAttr":$name,
492+
"mlir::Type":$storageType,
493+
"uint64_t":$size,
494+
"uint64_t":$offset,
495+
"bool":$isSigned);
496+
497+
let assemblyFormat = [{`<` struct($name,
498+
$storageType,
499+
$size,
500+
$offset,
501+
$isSigned)
502+
`>`
503+
}];
504+
505+
let builders = [
506+
AttrBuilder<(ins "llvm::StringRef":$name,
507+
"mlir::Type":$storageType,
508+
"uint64_t":$size,
509+
"uint64_t":$offset,
510+
"bool":$isSigned
511+
), [{
512+
return $_get($_ctxt, mlir::StringAttr::get($_ctxt, name), storageType,
513+
size, offset, isSigned);
514+
}]>
515+
];
516+
}
517+
518+
456519
#endif // LLVM_CLANG_CIR_DIALECT_IR_CIRATTRS_TD

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

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,85 @@ def GetGlobalOp : CIR_Op<"get_global",
16691669
}];
16701670
}
16711671

1672+
//===----------------------------------------------------------------------===//
1673+
// GetBitfieldOp
1674+
//===----------------------------------------------------------------------===//
1675+
1676+
def GetBitfieldOp : CIR_Op<"get_bitfield"> {
1677+
let summary = "Get the information for a bitfield member";
1678+
let description = [{
1679+
The `cir.get_bitfield` operation provides a load-like access to
1680+
a bit field of a record.
1681+
1682+
It expects a name if a bit field, a pointer to a storage in the
1683+
base record, a type of the storage, a name of the bitfield,
1684+
a size the bit field, an offset of the bit field and a sign.
1685+
1686+
A unit attribute `volatile` can be used to indicate a volatile load of the
1687+
bitfield.
1688+
1689+
Example:
1690+
Suppose we have a struct with multiple bitfields stored in
1691+
different members. The `cir.get_bitfield` operation gets the value
1692+
of the bitfield.
1693+
```C++
1694+
typedef struct {
1695+
int a : 4;
1696+
int b : 27;
1697+
int c : 17;
1698+
int d : 2;
1699+
int e : 15;
1700+
} S;
1701+
1702+
int load_bitfield(S& s) {
1703+
return s.e;
1704+
}
1705+
```
1706+
1707+
```mlir
1708+
// 'e' is in the storage with the index 1
1709+
!cir.record<struct "S" packed padded {!u64i, !u16i, !cir.array<!u8i x 2>}>
1710+
#bfi_e = #cir.bitfield_info<name = "e", storage_type = !u16i, size = 15,
1711+
offset = 0, is_signed = true>
1712+
1713+
%2 = cir.load %0 : !cir.ptr<!cir.ptr<!record_type>>, !cir.ptr<!record_type>
1714+
%3 = cir.get_member %2[1] {name = "e"} : !cir.ptr<!record_type>
1715+
-> !cir.ptr<!u16i>
1716+
%4 = cir.get_bitfield(#bfi_e, %3 : !cir.ptr<!u16i>) -> !s32i
1717+
```
1718+
}];
1719+
1720+
let arguments = (ins
1721+
Arg<CIR_PointerType, "the address to load from", [MemRead]>:$addr,
1722+
BitfieldInfoAttr:$bitfield_info,
1723+
UnitAttr:$is_volatile
1724+
);
1725+
1726+
let results = (outs CIR_IntType:$result);
1727+
1728+
let assemblyFormat = [{ `(`$bitfield_info `,` $addr attr-dict `:`
1729+
qualified(type($addr)) `)` `->` type($result) }];
1730+
1731+
let builders = [
1732+
OpBuilder<(ins "mlir::Type":$type,
1733+
"mlir::Value":$addr,
1734+
"mlir::Type":$storage_type,
1735+
"llvm::StringRef":$name,
1736+
"unsigned":$size,
1737+
"unsigned":$offset,
1738+
"bool":$is_signed,
1739+
"bool":$is_volatile
1740+
),
1741+
[{
1742+
BitfieldInfoAttr info =
1743+
BitfieldInfoAttr::get($_builder.getContext(),
1744+
name, storage_type,
1745+
size, offset, is_signed);
1746+
build($_builder, $_state, type, addr, info, is_volatile);
1747+
}]>
1748+
];
1749+
}
1750+
16721751
//===----------------------------------------------------------------------===//
16731752
// GetMemberOp
16741753
//===----------------------------------------------------------------------===//

clang/include/clang/CIR/LoweringHelpers.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,18 @@ std::optional<mlir::Attribute>
3737
lowerConstArrayAttr(cir::ConstArrayAttr constArr,
3838
const mlir::TypeConverter *converter);
3939

40+
mlir::Value getConstAPInt(mlir::OpBuilder &bld, mlir::Location loc,
41+
mlir::Type typ, const llvm::APInt &val);
42+
43+
mlir::Value getConst(mlir::OpBuilder &bld, mlir::Location loc, mlir::Type typ,
44+
unsigned val);
45+
46+
mlir::Value createShL(mlir::OpBuilder &bld, mlir::Value lhs, unsigned rhs);
47+
48+
mlir::Value createAShR(mlir::OpBuilder &bld, mlir::Value lhs, unsigned rhs);
49+
50+
mlir::Value createAnd(mlir::OpBuilder &bld, mlir::Value lhs,
51+
const llvm::APInt &rhs);
52+
53+
mlir::Value createLShR(mlir::OpBuilder &bld, mlir::Value lhs, unsigned rhs);
4054
#endif

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,8 @@ def fsample_profile_use_profi : Flag<["-"], "fsample-profile-use-profi">,
16981698
basic block counts to branch probabilities to fix them by extended
16991699
and re-engineered classic MCMF (min-cost max-flow) approach.}]>;
17001700
def fno_profile_sample_accurate : Flag<["-"], "fno-profile-sample-accurate">, Group<f_Group>;
1701+
def fno_sample_profile_use_profi : Flag<["-"], "fno-sample-profile-use-profi">,
1702+
Group<f_Group>;
17011703
def fno_auto_profile : Flag<["-"], "fno-auto-profile">, Group<f_Group>,
17021704
Alias<fno_profile_sample_use>;
17031705
def fauto_profile_EQ : Joined<["-"], "fauto-profile=">,
@@ -3487,7 +3489,8 @@ def fno_experimental_isel : Flag<["-"], "fno-experimental-isel">, Group<f_clang_
34873489
Alias<fno_global_isel>;
34883490
def fveclib : Joined<["-"], "fveclib=">, Group<f_Group>,
34893491
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
3490-
HelpText<"Use the given vector functions library">,
3492+
HelpText<"Use the given vector functions library.\n"
3493+
" Note: -fveclib=libmvec on AArch64 requires GLIBC 2.40 or newer.">,
34913494
HelpTextForVariants<[ClangOption, CC1Option],
34923495
"Use the given vector functions library.\n"
34933496
" Note: -fveclib={ArmPL,SLEEF,libmvec} implies -fno-math-errno.\n"

clang/include/clang/Sema/Scope.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,15 @@ class Scope {
158158
/// constructs, since they have the same behavior.
159159
OpenACCComputeConstructScope = 0x10000000,
160160

161+
/// This is the scope of an OpenACC Loop/Combined construct, which is used
162+
/// to determine whether a 'cache' construct variable reference is legal.
163+
OpenACCLoopConstructScope = 0x20000000,
164+
161165
/// This is a scope of type alias declaration.
162-
TypeAliasScope = 0x20000000,
166+
TypeAliasScope = 0x40000000,
163167

164168
/// This is a scope of friend declaration.
165-
FriendScope = 0x40000000,
169+
FriendScope = 0x80000000,
166170
};
167171

168172
private:
@@ -549,6 +553,10 @@ class Scope {
549553
return getFlags() & Scope::OpenACCComputeConstructScope;
550554
}
551555

556+
bool isOpenACCLoopConstructScope() const {
557+
return getFlags() & Scope::OpenACCLoopConstructScope;
558+
}
559+
552560
/// Determine if this scope (or its parents) are a compute construct. If the
553561
/// argument is provided, the search will stop at any of the specified scopes.
554562
/// Otherwise, it will stop only at the normal 'no longer search' scopes.

clang/include/clang/Sema/SemaOpenACC.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ class SemaOpenACC : public SemaBase {
117117
OpenACCDirectiveKind DirectiveKind = OpenACCDirectiveKind::Invalid;
118118
} TileInfo;
119119

120+
/// The 'cache' var-list requires some additional work to track variable
121+
/// references to make sure they are on the 'other' side of a `loop`. This
122+
/// structure is used during parse time to track vardecl use while parsing a
123+
/// cache var list.
124+
struct CacheParseInfo {
125+
bool ParsingCacheVarList = false;
126+
bool IsInvalidCacheRef = false;
127+
} CacheInfo;
128+
120129
/// A list of the active reduction clauses, which allows us to check that all
121130
/// vars on nested constructs for the same reduction var have the same
122131
/// reduction operator. Currently this is enforced against all constructs
@@ -861,6 +870,12 @@ class SemaOpenACC : public SemaBase {
861870
ExprResult ActOnIntExpr(OpenACCDirectiveKind DK, OpenACCClauseKind CK,
862871
SourceLocation Loc, Expr *IntExpr);
863872

873+
/// Called right before a 'var' is parsed, so we can set the state for parsing
874+
/// a 'cache' var.
875+
void ActOnStartParseVar(OpenACCDirectiveKind DK, OpenACCClauseKind CK);
876+
/// Called only if the parse of a 'var' was invalid, else 'ActOnVar' should be
877+
/// called.
878+
void ActOnInvalidParseVar();
864879
/// Called when encountering a 'var' for OpenACC, ensures it is actually a
865880
/// declaration reference to a variable of the correct type.
866881
ExprResult ActOnVar(OpenACCDirectiveKind DK, OpenACCClauseKind CK,
@@ -913,6 +928,10 @@ class SemaOpenACC : public SemaBase {
913928
OpenACCDirectiveKind DK, OpenACCGangKind GK,
914929
Expr *E);
915930

931+
// Called when a declaration is referenced, so that we can make sure certain
932+
// clauses don't do the 'wrong' thing/have incorrect references.
933+
void CheckDeclReference(SourceLocation Loc, Expr *E, Decl *D);
934+
916935
// Does the checking for a 'gang' clause that needs to be done in dependent
917936
// and not dependent cases.
918937
OpenACCClause *

clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,9 @@ class SMTConv {
598598
if (APSIntBitwidth == 1 && Ty.isNull())
599599
return {Int.extend(Ctx.getTypeSize(Ctx.BoolTy)),
600600
getAPSIntType(Ctx, NewInt)};
601+
else if (APSIntBitwidth == 1 && !Ty.isNull())
602+
return {Int.extend(Ctx.getTypeSize(getAPSIntType(Ctx, Int))),
603+
getAPSIntType(Ctx, NewInt)};
601604
if (llvm::isPowerOf2_32(APSIntBitwidth) || Ty.isNull())
602605
return {Int, Ty};
603606
return {Int.extend(Ctx.getTypeSize(Ty)), Ty};

clang/lib/CIR/CodeGen/CIRGenBuilder.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENBUILDER_H
1111

1212
#include "Address.h"
13+
#include "CIRGenRecordLayout.h"
1314
#include "CIRGenTypeCache.h"
1415
#include "clang/CIR/Interfaces/CIRTypeInterfaces.h"
1516
#include "clang/CIR/MissingFeatures.h"
@@ -392,6 +393,15 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
392393

393394
return createGlobal(module, loc, uniqueName, type, linkage);
394395
}
396+
397+
mlir::Value createGetBitfield(mlir::Location loc, mlir::Type resultType,
398+
mlir::Value addr, mlir::Type storageType,
399+
const CIRGenBitFieldInfo &info,
400+
bool isLvalueVolatile, bool useVolatile) {
401+
return create<cir::GetBitfieldOp>(loc, resultType, addr, storageType,
402+
info.name, info.size, info.offset,
403+
info.isSigned, isLvalueVolatile);
404+
}
395405
};
396406

397407
} // namespace clang::CIRGen

0 commit comments

Comments
 (0)