Skip to content

Commit 615b91b

Browse files
committed
Merge from 'main' to 'sycl-web' (59 commits)
CONFLICT (content): Merge conflict in clang/lib/AST/Type.cpp
2 parents 462e6c9 + 92b03e4 commit 615b91b

File tree

586 files changed

+7963
-3711
lines changed

Some content is hidden

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

586 files changed

+7963
-3711
lines changed

bolt/docs/BinaryAnalysis.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,6 @@ The following are current known cases of false negatives:
180180
[prototype branch](
181181
https://github.com/llvm/llvm-project/compare/main...kbeyls:llvm-project:bolt-gadget-scanner-prototype).
182182

183-
BOLT cannot currently handle functions with `cfi_negate_ra_state` correctly,
184-
i.e. any binaries built with `-mbranch-protection=pac-ret`. The scanner is meant
185-
to be used on specifically such binaries, so this is a major limitation! Work is
186-
going on in PR [#120064](https://github.com/llvm/llvm-project/pull/120064) to
187-
fix this.
188-
189183
## How to add your own binary analysis
190184

191185
_TODO: this section needs to be written. Ideally, we should have a simple

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ extern cl::opt<bool> StrictMode;
6565
extern cl::opt<bool> UpdateDebugSections;
6666
extern cl::opt<unsigned> Verbosity;
6767

68+
extern bool BinaryAnalysisMode;
69+
extern bool HeatmapMode;
6870
extern bool processAllFunctions();
6971

7072
static cl::opt<bool> CheckEncoding(
@@ -2760,13 +2762,19 @@ struct CFISnapshot {
27602762
}
27612763
case MCCFIInstruction::OpAdjustCfaOffset:
27622764
case MCCFIInstruction::OpWindowSave:
2763-
case MCCFIInstruction::OpNegateRAState:
27642765
case MCCFIInstruction::OpNegateRAStateWithPC:
27652766
case MCCFIInstruction::OpLLVMDefAspaceCfa:
27662767
case MCCFIInstruction::OpLabel:
27672768
case MCCFIInstruction::OpValOffset:
27682769
llvm_unreachable("unsupported CFI opcode");
27692770
break;
2771+
case MCCFIInstruction::OpNegateRAState:
2772+
if (!(opts::BinaryAnalysisMode || opts::HeatmapMode)) {
2773+
llvm_unreachable("BOLT-ERROR: binaries using pac-ret hardening (e.g. "
2774+
"as produced by '-mbranch-protection=pac-ret') are "
2775+
"currently not supported by BOLT.");
2776+
}
2777+
break;
27702778
case MCCFIInstruction::OpRememberState:
27712779
case MCCFIInstruction::OpRestoreState:
27722780
case MCCFIInstruction::OpGnuArgsSize:
@@ -2900,13 +2908,19 @@ struct CFISnapshotDiff : public CFISnapshot {
29002908
return CFAReg == Instr.getRegister() && CFAOffset == Instr.getOffset();
29012909
case MCCFIInstruction::OpAdjustCfaOffset:
29022910
case MCCFIInstruction::OpWindowSave:
2903-
case MCCFIInstruction::OpNegateRAState:
29042911
case MCCFIInstruction::OpNegateRAStateWithPC:
29052912
case MCCFIInstruction::OpLLVMDefAspaceCfa:
29062913
case MCCFIInstruction::OpLabel:
29072914
case MCCFIInstruction::OpValOffset:
29082915
llvm_unreachable("unsupported CFI opcode");
29092916
return false;
2917+
case MCCFIInstruction::OpNegateRAState:
2918+
if (!(opts::BinaryAnalysisMode || opts::HeatmapMode)) {
2919+
llvm_unreachable("BOLT-ERROR: binaries using pac-ret hardening (e.g. "
2920+
"as produced by '-mbranch-protection=pac-ret') are "
2921+
"currently not supported by BOLT.");
2922+
}
2923+
break;
29102924
case MCCFIInstruction::OpRememberState:
29112925
case MCCFIInstruction::OpRestoreState:
29122926
case MCCFIInstruction::OpGnuArgsSize:
@@ -3051,13 +3065,19 @@ BinaryFunction::unwindCFIState(int32_t FromState, int32_t ToState,
30513065
break;
30523066
case MCCFIInstruction::OpAdjustCfaOffset:
30533067
case MCCFIInstruction::OpWindowSave:
3054-
case MCCFIInstruction::OpNegateRAState:
30553068
case MCCFIInstruction::OpNegateRAStateWithPC:
30563069
case MCCFIInstruction::OpLLVMDefAspaceCfa:
30573070
case MCCFIInstruction::OpLabel:
30583071
case MCCFIInstruction::OpValOffset:
30593072
llvm_unreachable("unsupported CFI opcode");
30603073
break;
3074+
case MCCFIInstruction::OpNegateRAState:
3075+
if (!(opts::BinaryAnalysisMode || opts::HeatmapMode)) {
3076+
llvm_unreachable("BOLT-ERROR: binaries using pac-ret hardening (e.g. "
3077+
"as produced by '-mbranch-protection=pac-ret') are "
3078+
"currently not supported by BOLT.");
3079+
}
3080+
break;
30613081
case MCCFIInstruction::OpGnuArgsSize:
30623082
// do not affect CFI state
30633083
break;

clang/docs/ReleaseNotes.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,23 @@ C Language Changes
171171
``-Wenum-conversion`` and ``-Wimplicit-int-enum-cast``. This conversion is an
172172
int-to-enum conversion because the enumeration on the right-hand side is
173173
promoted to ``int`` before the assignment.
174+
- Added ``-Wunterminated-string-initialization``, grouped under ``-Wextra``,
175+
which diagnoses an initialization from a string literal where only the null
176+
terminator cannot be stored. e.g.,
177+
178+
.. code-block:: c
179+
180+
181+
char buf1[3] = "foo"; // -Wunterminated-string-initialization
182+
char buf2[3] = "flarp"; // -Wexcess-initializers
183+
184+
This diagnostic can be suppressed by adding the new ``nonstring`` attribute
185+
to the field or variable being initialized. #GH137705
186+
- Added ``-Wc++-unterminated-string-initialization``, grouped under
187+
``-Wc++-compat``, which also diagnoses the same cases as
188+
``-Wunterminated-string-initialization``. However, this diagnostic is not
189+
silenced by the ``nonstring`` attribute as these initializations are always
190+
incompatible with C++.
174191

175192
C2y Feature Support
176193
^^^^^^^^^^^^^^^^^^^
@@ -244,6 +261,8 @@ New Compiler Flags
244261
The feature has `existed <https://clang.llvm.org/docs/SourceBasedCodeCoverage.html#running-the-instrumented-program>`_)
245262
for a while and this is just a user facing option.
246263

264+
- New option ``-ftime-report-json`` added which outputs the same timing data as `-ftime-report` but formatted as JSON.
265+
247266
Deprecated Compiler Flags
248267
-------------------------
249268

@@ -494,6 +513,9 @@ Bug Fixes in This Version
494513
evaluation. The crashes were happening during diagnostics emission due to
495514
unimplemented statement printer. (#GH132641)
496515
- Fixed visibility calculation for template functions. (#GH103477)
516+
- Fixed a bug where an attribute before a ``pragma clang attribute`` or
517+
``pragma clang __debug`` would cause an assertion. Instead, this now diagnoses
518+
the invalid attribute location appropriately. (#GH137861)
497519

498520
Bug Fixes to Compiler Builtins
499521
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/AST/Mangle.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ struct ThisAdjustment;
4040
struct ThunkInfo;
4141
class VarDecl;
4242

43+
/// Extract mangling function name from MangleContext such that swift can call
44+
/// it to prepare for ObjCDirect in swift.
45+
void mangleObjCMethodName(raw_ostream &OS, bool includePrefixByte,
46+
bool isInstanceMethod, StringRef ClassName,
47+
std::optional<StringRef> CategoryName,
48+
StringRef MethodName);
49+
4350
/// MangleContext - Context for tracking state which persists across multiple
4451
/// calls to the C++ name mangler.
4552
class MangleContext {

clang/include/clang/Basic/Attr.td

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4896,6 +4896,7 @@ def AssertCapability : InheritableAttr {
48964896
let ParseArgumentsAsUnevaluated = 1;
48974897
let InheritEvenIfAlreadyPresent = 1;
48984898
let Args = [VariadicExprArgument<"Args">];
4899+
let AcceptsExprPack = 1;
48994900
let Accessors = [Accessor<"isShared",
49004901
[Clang<"assert_shared_capability", 0>,
49014902
GNU<"assert_shared_lock">]>];
@@ -4913,6 +4914,7 @@ def AcquireCapability : InheritableAttr {
49134914
let ParseArgumentsAsUnevaluated = 1;
49144915
let InheritEvenIfAlreadyPresent = 1;
49154916
let Args = [VariadicExprArgument<"Args">];
4917+
let AcceptsExprPack = 1;
49164918
let Accessors = [Accessor<"isShared",
49174919
[Clang<"acquire_shared_capability", 0>,
49184920
GNU<"shared_lock_function">]>];
@@ -4930,6 +4932,7 @@ def TryAcquireCapability : InheritableAttr {
49304932
let ParseArgumentsAsUnevaluated = 1;
49314933
let InheritEvenIfAlreadyPresent = 1;
49324934
let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
4935+
let AcceptsExprPack = 1;
49334936
let Accessors = [Accessor<"isShared",
49344937
[Clang<"try_acquire_shared_capability", 0>,
49354938
GNU<"shared_trylock_function">]>];
@@ -4947,6 +4950,7 @@ def ReleaseCapability : InheritableAttr {
49474950
let ParseArgumentsAsUnevaluated = 1;
49484951
let InheritEvenIfAlreadyPresent = 1;
49494952
let Args = [VariadicExprArgument<"Args">];
4953+
let AcceptsExprPack = 1;
49504954
let Accessors = [Accessor<"isShared",
49514955
[Clang<"release_shared_capability", 0>]>,
49524956
Accessor<"isGeneric",
@@ -4961,6 +4965,7 @@ def RequiresCapability : InheritableAttr {
49614965
Clang<"requires_shared_capability", 0>,
49624966
Clang<"shared_locks_required", 0>];
49634967
let Args = [VariadicExprArgument<"Args">];
4968+
let AcceptsExprPack = 1;
49644969
let LateParsed = LateAttrParseStandard;
49654970
let TemplateDependent = 1;
49664971
let ParseArgumentsAsUnevaluated = 1;
@@ -5003,6 +5008,7 @@ def PtGuardedBy : InheritableAttr {
50035008
def AcquiredAfter : InheritableAttr {
50045009
let Spellings = [GNU<"acquired_after">];
50055010
let Args = [VariadicExprArgument<"Args">];
5011+
let AcceptsExprPack = 1;
50065012
let LateParsed = LateAttrParseExperimentalExt;
50075013
let TemplateDependent = 1;
50085014
let ParseArgumentsAsUnevaluated = 1;
@@ -5014,6 +5020,7 @@ def AcquiredAfter : InheritableAttr {
50145020
def AcquiredBefore : InheritableAttr {
50155021
let Spellings = [GNU<"acquired_before">];
50165022
let Args = [VariadicExprArgument<"Args">];
5023+
let AcceptsExprPack = 1;
50175024
let LateParsed = LateAttrParseExperimentalExt;
50185025
let TemplateDependent = 1;
50195026
let ParseArgumentsAsUnevaluated = 1;
@@ -5035,6 +5042,7 @@ def LockReturned : InheritableAttr {
50355042
def LocksExcluded : InheritableAttr {
50365043
let Spellings = [GNU<"locks_excluded">];
50375044
let Args = [VariadicExprArgument<"Args">];
5045+
let AcceptsExprPack = 1;
50385046
let LateParsed = LateAttrParseStandard;
50395047
let TemplateDependent = 1;
50405048
let ParseArgumentsAsUnevaluated = 1;
@@ -5792,20 +5800,25 @@ def HLSLResourceBinding: InheritableAttr {
57925800

57935801
private:
57945802
RegisterType RegType;
5795-
unsigned SlotNumber;
5803+
std::optional<unsigned> SlotNumber;
57965804
unsigned SpaceNumber;
57975805

57985806
public:
5799-
void setBinding(RegisterType RT, unsigned SlotNum, unsigned SpaceNum) {
5807+
void setBinding(RegisterType RT, std::optional<unsigned> SlotNum, unsigned SpaceNum) {
58005808
RegType = RT;
58015809
SlotNumber = SlotNum;
58025810
SpaceNumber = SpaceNum;
58035811
}
5812+
bool isImplicit() const {
5813+
return !SlotNumber.has_value();
5814+
}
58045815
RegisterType getRegisterType() const {
5816+
assert(!isImplicit() && "binding does not have register slot");
58055817
return RegType;
58065818
}
58075819
unsigned getSlotNumber() const {
5808-
return SlotNumber;
5820+
assert(!isImplicit() && "binding does not have register slot");
5821+
return SlotNumber.value();
58095822
}
58105823
unsigned getSpaceNumber() const {
58115824
return SpaceNumber;
@@ -6064,3 +6077,9 @@ def OpenACCRoutineDecl :InheritableAttr {
60646077
void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const;
60656078
}];
60666079
}
6080+
6081+
def NonString : InheritableAttr {
6082+
let Spellings = [GCC<"nonstring">];
6083+
let Subjects = SubjectList<[Var, Field]>;
6084+
let Documentation = [NonStringDocs];
6085+
}

clang/include/clang/Basic/AttrDocs.td

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11017,3 +11017,18 @@ Declares that a function potentially allocates heap memory, and prevents any pot
1101711017
of ``nonallocating`` by the compiler.
1101811018
}];
1101911019
}
11020+
11021+
def NonStringDocs : Documentation {
11022+
let Category = DocCatDecl;
11023+
let Content = [{
11024+
The ``nonstring`` attribute can be applied to the declaration of a variable or
11025+
a field whose type is a character array to specify that the character array is
11026+
not intended to behave like a null-terminated string. This will silence
11027+
diagnostics with code like:
11028+
11029+
.. code-block:: c
11030+
11031+
char BadStr[3] = "foo"; // No space for the null terminator, diagnosed
11032+
__attribute__((nonstring)) char NotAStr[3] = "foo"; // Not diagnosed
11033+
}];
11034+
}

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,9 @@ CODEGENOPT(SpeculativeLoadHardening, 1, 0) ///< Enable speculative load hardenin
318318
CODEGENOPT(FineGrainedBitfieldAccesses, 1, 0) ///< Enable fine-grained bitfield accesses.
319319
CODEGENOPT(StrictEnums , 1, 0) ///< Optimize based on strict enum definition.
320320
CODEGENOPT(StrictVTablePointers, 1, 0) ///< Optimize based on the strict vtable pointers
321-
CODEGENOPT(TimePasses , 1, 0) ///< Set when -ftime-report or -ftime-report= is enabled.
321+
CODEGENOPT(TimePasses , 1, 0) ///< Set when -ftime-report or -ftime-report= or -ftime-report-json is enabled.
322322
CODEGENOPT(TimePassesPerRun , 1, 0) ///< Set when -ftime-report=per-pass-run is enabled.
323+
CODEGENOPT(TimePassesJson , 1, 0) ///< Set when -ftime-report-json is enabled.
323324
CODEGENOPT(TimeTrace , 1, 0) ///< Set when -ftime-trace is enabled.
324325
VALUE_CODEGENOPT(TimeTraceGranularity, 32, 500) ///< Minimum time granularity (in microseconds),
325326
///< traced by time profiler

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,19 @@ def BuiltinRequiresHeader : DiagGroup<"builtin-requires-header">;
157157
def C99Compat : DiagGroup<"c99-compat">;
158158
def C23Compat : DiagGroup<"c23-compat">;
159159
def : DiagGroup<"c2x-compat", [C23Compat]>;
160+
def InitStringTooLongMissingNonString :
161+
DiagGroup<"unterminated-string-initialization">;
162+
def InitStringTooLongForCpp :
163+
DiagGroup<"c++-unterminated-string-initialization">;
160164
def HiddenCppDecl : DiagGroup<"c++-hidden-decl">;
161165
def DefaultConstInitUnsafe : DiagGroup<"default-const-init-unsafe">;
162166
def DefaultConstInit : DiagGroup<"default-const-init", [DefaultConstInitUnsafe]>;
163167
def ImplicitVoidPtrCast : DiagGroup<"implicit-void-ptr-cast">;
164168
def ImplicitIntToEnumCast : DiagGroup<"implicit-int-enum-cast",
165169
[ImplicitEnumEnumCast]>;
166170
def CXXCompat: DiagGroup<"c++-compat", [ImplicitVoidPtrCast, DefaultConstInit,
167-
ImplicitIntToEnumCast, HiddenCppDecl]>;
171+
ImplicitIntToEnumCast, HiddenCppDecl,
172+
InitStringTooLongForCpp]>;
168173

169174
def ExternCCompat : DiagGroup<"extern-c-compat">;
170175
def KeywordCompat : DiagGroup<"keyword-compat">;
@@ -1152,6 +1157,7 @@ def Extra : DiagGroup<"extra", [
11521157
StringConcatation,
11531158
FUseLdPath,
11541159
CastFunctionTypeMismatch,
1160+
InitStringTooLongMissingNonString,
11551161
]>;
11561162

11571163
def Most : DiagGroup<"most", [

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3888,6 +3888,9 @@ def err_attribute_weakref_without_alias : Error<
38883888
"weakref declaration of %0 must also have an alias attribute">;
38893889
def err_alias_not_supported_on_darwin : Error <
38903890
"aliases are not supported on darwin">;
3891+
def warn_attribute_non_character_array : Warning<
3892+
"%0%select{ attribute|}1 only applies to fields or variables of character "
3893+
"array type; type is %2">, InGroup<IgnoredAttributes>;
38913894
def warn_attribute_wrong_decl_type_str : Warning<
38923895
"%0%select{ attribute|}1 only applies to %2">, InGroup<IgnoredAttributes>;
38933896
def err_attribute_wrong_decl_type_str : Error<
@@ -6492,6 +6495,15 @@ def err_initializer_string_for_char_array_too_long : Error<
64926495
def ext_initializer_string_for_char_array_too_long : ExtWarn<
64936496
"initializer-string for char array is too long">,
64946497
InGroup<ExcessInitializers>;
6498+
def warn_initializer_string_for_char_array_too_long_no_nonstring : Warning<
6499+
"initializer-string for character array is too long, array size is %0 but "
6500+
"initializer has size %1 (including the null terminating character); did you "
6501+
"mean to use the 'nonstring' attribute?">,
6502+
InGroup<InitStringTooLongMissingNonString>, DefaultIgnore;
6503+
def warn_initializer_string_for_char_array_too_long_for_cpp : Warning<
6504+
"initializer-string for character array is too long for C++, array size is "
6505+
"%0 but initializer has size %1 (including the null terminating character)">,
6506+
InGroup<InitStringTooLongForCpp>, DefaultIgnore;
64956507
def warn_missing_field_initializers : Warning<
64966508
"missing field %0 initializer">,
64976509
InGroup<MissingFieldInitializers>, DefaultIgnore;

clang/include/clang/Basic/LangOptions.def

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,21 @@ BENIGN_ENUM_LANGOPT(DefaultFPContractMode, FPModeKind, 2, FPM_Off, "FP contracti
375375
COMPATIBLE_LANGOPT(ExpStrictFP, 1, false, "Enable experimental strict floating point")
376376
BENIGN_LANGOPT(RoundingMath, 1, false, "Do not assume default floating-point rounding behavior")
377377
BENIGN_ENUM_LANGOPT(FPExceptionMode, FPExceptionModeKind, 2, FPE_Default, "FP Exception Behavior Mode type")
378+
379+
#if defined(__clang__) && defined(__has_warning)
380+
#if __has_warning("-Wpreferred-type-bitfield-enum-conversion")
381+
// FIXME: Remove this once the warning is fixed, https://llvm.org/PR137600
382+
#pragma clang diagnostic push
383+
#pragma clang diagnostic ignored "-Wpreferred-type-bitfield-enum-conversion"
384+
#endif
385+
#endif
378386
BENIGN_ENUM_LANGOPT(FPEvalMethod, FPEvalMethodKind, 3, FEM_UnsetOnCommandLine, "FP type used for floating point arithmetic")
387+
#if defined(__clang__) && defined(__has_warning)
388+
#if __has_warning("-Wpreferred-type-bitfield-enum-conversion")
389+
#pragma clang diagnostic pop
390+
#endif
391+
#endif
392+
379393
ENUM_LANGOPT(Float16ExcessPrecision, ExcessPrecisionKind, 2, FPP_Standard, "Intermediate truncation behavior for Float16 arithmetic")
380394
ENUM_LANGOPT(BFloat16ExcessPrecision, ExcessPrecisionKind, 2, FPP_Standard, "Intermediate truncation behavior for BFloat16 arithmetic")
381395
BENIGN_ENUM_LANGOPT(FPAccuracy, FPAccuracyKind, 3, FPA_Default, "Accuracy for floating point operations and library functions")

0 commit comments

Comments
 (0)