Skip to content

Commit ffa4ab5

Browse files
Merge branch 'main' into FixAArch64LdStOptInstrRef
2 parents 81ba3ba + b02f2e8 commit ffa4ab5

File tree

823 files changed

+9386
-5631
lines changed

Some content is hidden

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

823 files changed

+9386
-5631
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: 20 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
^^^^^^^^^^^^^^^^^^^
@@ -494,6 +511,9 @@ Bug Fixes in This Version
494511
evaluation. The crashes were happening during diagnostics emission due to
495512
unimplemented statement printer. (#GH132641)
496513
- Fixed visibility calculation for template functions. (#GH103477)
514+
- Fixed a bug where an attribute before a ``pragma clang attribute`` or
515+
``pragma clang __debug`` would cause an assertion. Instead, this now diagnoses
516+
the invalid attribute location appropriately. (#GH137861)
497517

498518
Bug Fixes to Compiler Builtins
499519
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4752,20 +4752,25 @@ def HLSLResourceBinding: InheritableAttr {
47524752

47534753
private:
47544754
RegisterType RegType;
4755-
unsigned SlotNumber;
4755+
std::optional<unsigned> SlotNumber;
47564756
unsigned SpaceNumber;
47574757

47584758
public:
4759-
void setBinding(RegisterType RT, unsigned SlotNum, unsigned SpaceNum) {
4759+
void setBinding(RegisterType RT, std::optional<unsigned> SlotNum, unsigned SpaceNum) {
47604760
RegType = RT;
47614761
SlotNumber = SlotNum;
47624762
SpaceNumber = SpaceNum;
47634763
}
4764+
bool isImplicit() const {
4765+
return !SlotNumber.has_value();
4766+
}
47644767
RegisterType getRegisterType() const {
4768+
assert(!isImplicit() && "binding does not have register slot");
47654769
return RegType;
47664770
}
47674771
unsigned getSlotNumber() const {
4768-
return SlotNumber;
4772+
assert(!isImplicit() && "binding does not have register slot");
4773+
return SlotNumber.value();
47694774
}
47704775
unsigned getSpaceNumber() const {
47714776
return SpaceNumber;
@@ -5024,3 +5029,9 @@ def OpenACCRoutineDecl :InheritableAttr {
50245029
void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const;
50255030
}];
50265031
}
5032+
5033+
def NonString : InheritableAttr {
5034+
let Spellings = [GCC<"nonstring">];
5035+
let Subjects = SubjectList<[Var, Field]>;
5036+
let Documentation = [NonStringDocs];
5037+
}

clang/include/clang/Basic/AttrDocs.td

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9294,3 +9294,18 @@ Declares that a function potentially allocates heap memory, and prevents any pot
92949294
of ``nonallocating`` by the compiler.
92959295
}];
92969296
}
9297+
9298+
def NonStringDocs : Documentation {
9299+
let Category = DocCatDecl;
9300+
let Content = [{
9301+
The ``nonstring`` attribute can be applied to the declaration of a variable or
9302+
a field whose type is a character array to specify that the character array is
9303+
not intended to behave like a null-terminated string. This will silence
9304+
diagnostics with code like:
9305+
9306+
.. code-block:: c
9307+
9308+
char BadStr[3] = "foo"; // No space for the null terminator, diagnosed
9309+
__attribute__((nonstring)) char NotAStr[3] = "foo"; // Not diagnosed
9310+
}];
9311+
}

clang/include/clang/Basic/Builtins.td

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4801,6 +4801,18 @@ def HLSLResourceGetPointer : LangBuiltin<"HLSL_LANG"> {
48014801
let Prototype = "void(...)";
48024802
}
48034803

4804+
def HLSLResourceUninitializedHandle : LangBuiltin<"HLSL_LANG"> {
4805+
let Spellings = ["__builtin_hlsl_resource_uninitializedhandle"];
4806+
let Attributes = [NoThrow];
4807+
let Prototype = "void(...)";
4808+
}
4809+
4810+
def HLSLResourceHandleFromBinding : LangBuiltin<"HLSL_LANG"> {
4811+
let Spellings = ["__builtin_hlsl_resource_handlefrombinding"];
4812+
let Attributes = [NoThrow];
4813+
let Prototype = "void(...)";
4814+
}
4815+
48044816
def HLSLAll : LangBuiltin<"HLSL_LANG"> {
48054817
let Spellings = ["__builtin_hlsl_all"];
48064818
let Attributes = [NoThrow, Const];

clang/include/clang/Basic/DiagnosticGroups.td

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

168173
def ExternCCompat : DiagGroup<"extern-c-compat">;
169174
def KeywordCompat : DiagGroup<"keyword-compat">;
@@ -1143,6 +1148,7 @@ def Extra : DiagGroup<"extra", [
11431148
StringConcatation,
11441149
FUseLdPath,
11451150
CastFunctionTypeMismatch,
1151+
InitStringTooLongMissingNonString,
11461152
]>;
11471153

11481154
def Most : DiagGroup<"most", [

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3804,6 +3804,9 @@ def err_attribute_weakref_without_alias : Error<
38043804
"weakref declaration of %0 must also have an alias attribute">;
38053805
def err_alias_not_supported_on_darwin : Error <
38063806
"aliases are not supported on darwin">;
3807+
def warn_attribute_non_character_array : Warning<
3808+
"%0%select{ attribute|}1 only applies to fields or variables of character "
3809+
"array type; type is %2">, InGroup<IgnoredAttributes>;
38073810
def warn_attribute_wrong_decl_type_str : Warning<
38083811
"%0%select{ attribute|}1 only applies to %2">, InGroup<IgnoredAttributes>;
38093812
def err_attribute_wrong_decl_type_str : Error<
@@ -6404,6 +6407,15 @@ def err_initializer_string_for_char_array_too_long : Error<
64046407
def ext_initializer_string_for_char_array_too_long : ExtWarn<
64056408
"initializer-string for char array is too long">,
64066409
InGroup<ExcessInitializers>;
6410+
def warn_initializer_string_for_char_array_too_long_no_nonstring : Warning<
6411+
"initializer-string for character array is too long, array size is %0 but "
6412+
"initializer has size %1 (including the null terminating character); did you "
6413+
"mean to use the 'nonstring' attribute?">,
6414+
InGroup<InitStringTooLongMissingNonString>, DefaultIgnore;
6415+
def warn_initializer_string_for_char_array_too_long_for_cpp : Warning<
6416+
"initializer-string for character array is too long for C++, array size is "
6417+
"%0 but initializer has size %1 (including the null terminating character)">,
6418+
InGroup<InitStringTooLongForCpp>, DefaultIgnore;
64076419
def warn_missing_field_initializers : Warning<
64086420
"missing field %0 initializer">,
64096421
InGroup<MissingFieldInitializers>, DefaultIgnore;

clang/include/clang/Basic/LangOptions.def

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,21 @@ BENIGN_ENUM_LANGOPT(DefaultFPContractMode, FPModeKind, 2, FPM_Off, "FP contracti
347347
COMPATIBLE_LANGOPT(ExpStrictFP, 1, false, "Enable experimental strict floating point")
348348
BENIGN_LANGOPT(RoundingMath, 1, false, "Do not assume default floating-point rounding behavior")
349349
BENIGN_ENUM_LANGOPT(FPExceptionMode, FPExceptionModeKind, 2, FPE_Default, "FP Exception Behavior Mode type")
350+
351+
#if defined(__clang__) && defined(__has_warning)
352+
#if __has_warning("-Wpreferred-type-bitfield-enum-conversion")
353+
// FIXME: Remove this once the warning is fixed, https://llvm.org/PR137600
354+
#pragma clang diagnostic push
355+
#pragma clang diagnostic ignored "-Wpreferred-type-bitfield-enum-conversion"
356+
#endif
357+
#endif
350358
BENIGN_ENUM_LANGOPT(FPEvalMethod, FPEvalMethodKind, 3, FEM_UnsetOnCommandLine, "FP type used for floating point arithmetic")
359+
#if defined(__clang__) && defined(__has_warning)
360+
#if __has_warning("-Wpreferred-type-bitfield-enum-conversion")
361+
#pragma clang diagnostic pop
362+
#endif
363+
#endif
364+
351365
ENUM_LANGOPT(Float16ExcessPrecision, ExcessPrecisionKind, 2, FPP_Standard, "Intermediate truncation behavior for Float16 arithmetic")
352366
ENUM_LANGOPT(BFloat16ExcessPrecision, ExcessPrecisionKind, 2, FPP_Standard, "Intermediate truncation behavior for BFloat16 arithmetic")
353367
LANGOPT(NoBitFieldTypeAlign , 1, 0, "bit-field type alignment")

0 commit comments

Comments
 (0)