Skip to content

Commit 086460c

Browse files
committed
Merge branch 'main' of https://github.com/llvm/llvm-project into fix/147217
2 parents 7bbd741 + 147cfc8 commit 086460c

File tree

276 files changed

+7777
-4518
lines changed

Some content is hidden

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

276 files changed

+7777
-4518
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ Bug Fixes in This Version
150150

151151
Bug Fixes to Compiler Builtins
152152
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
153+
- Fix an ambiguous reference to the builtin `type_info` (available when using
154+
`-fms-compatibility`) with modules. (#GH38400)
153155

154156
Bug Fixes to Attribute Support
155157
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/docs/analyzer/checkers.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3086,6 +3086,23 @@ Either the comparison is useless or there is division by zero.
30863086
if (x == 0) { } // warn
30873087
}
30883088
3089+
.. _alpha-core-StoreToImmutable:
3090+
3091+
alpha.core.StoreToImmutable (C, C++)
3092+
""""""""""""""""""""""""""""""""""""
3093+
Check for writes to immutable memory regions. This implements part of SEI CERT Rule ENV30-C.
3094+
3095+
This checker detects attempts to write to memory regions that are marked as immutable,
3096+
including const variables, string literals, and other const-qualified memory.
3097+
3098+
.. literalinclude:: checkers/storetoimmutable_example.cpp
3099+
:language: cpp
3100+
3101+
**Solution**
3102+
3103+
Avoid writing to const-qualified memory regions. If you need to modify the data,
3104+
remove the const qualifier from the original declaration or use a mutable copy.
3105+
30893106
alpha.cplusplus
30903107
^^^^^^^^^^^^^^^
30913108
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const int global_const = 42;
2+
3+
struct TestStruct {
4+
const int x;
5+
int y;
6+
};
7+
8+
void immutable_violation_examples() {
9+
*(int *)&global_const = 100; // warn: Trying to write to immutable memory
10+
11+
const int local_const = 42;
12+
*(int *)&local_const = 43; // warn: Trying to write to immutable memory
13+
14+
// NOTE: The following is reported in C++, but not in C, as the analyzer
15+
// treats string literals as non-const char arrays in C mode.
16+
char *ptr_to_str_literal = (char *)"hello";
17+
ptr_to_str_literal[0] = 'H'; // warn: Trying to write to immutable memory
18+
19+
TestStruct s = {1, 2};
20+
*(int *)&s.x = 10; // warn: Trying to write to immutable memory
21+
}

clang/include/clang/AST/ASTContext.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,9 @@ class ASTContext : public RefCountedBase<ASTContext> {
12901290
// Implicitly-declared type 'struct _GUID'.
12911291
mutable TagDecl *MSGuidTagDecl = nullptr;
12921292

1293+
// Implicitly-declared type 'struct type_info'.
1294+
mutable TagDecl *MSTypeInfoTagDecl = nullptr;
1295+
12931296
/// Keep track of CUDA/HIP device-side variables ODR-used by host code.
12941297
/// This does not include extern shared variables used by device host
12951298
/// functions as addresses of shared variables are per warp, therefore
@@ -2388,6 +2391,15 @@ class ASTContext : public RefCountedBase<ASTContext> {
23882391
return getTagDeclType(MSGuidTagDecl);
23892392
}
23902393

2394+
/// Retrieve the implicitly-predeclared 'struct type_info' declaration.
2395+
TagDecl *getMSTypeInfoTagDecl() const {
2396+
// Lazily create this type on demand - it's only needed for MS builds.
2397+
if (!MSTypeInfoTagDecl) {
2398+
MSTypeInfoTagDecl = buildImplicitRecord("type_info");
2399+
}
2400+
return MSTypeInfoTagDecl;
2401+
}
2402+
23912403
/// Return whether a declaration to a builtin is allowed to be
23922404
/// overloaded/redeclared.
23932405
bool canBuiltinBeRedeclared(const FunctionDecl *) const;

clang/include/clang/AST/DeclID.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ enum PredefinedDeclIDs {
7777
/// The internal '__NSConstantString' tag type.
7878
PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID,
7979

80+
/// The predeclared 'type_info' struct.
81+
PREDEF_DECL_BUILTIN_MS_TYPE_INFO_TAG_ID,
82+
8083
#define BuiltinTemplate(BTName) PREDEF_DECL##BTName##_ID,
8184
#include "clang/Basic/BuiltinTemplates.inc"
8285

clang/include/clang/Basic/Attr.td

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,22 +1059,13 @@ def AVRSignal : InheritableAttr, TargetSpecificAttr<TargetAVR> {
10591059
def AsmLabel : InheritableAttr {
10601060
let Spellings = [CustomKeyword<"asm">, CustomKeyword<"__asm__">];
10611061
let Args = [
1062-
// Label specifies the mangled name for the decl.
1063-
StringArgument<"Label">,
1064-
1065-
// IsLiteralLabel specifies whether the label is literal (i.e. suppresses
1066-
// the global C symbol prefix) or not. If not, the mangle-suppression prefix
1067-
// ('\01') is omitted from the decl name at the LLVM IR level.
1068-
//
1069-
// Non-literal labels are used by some external AST sources like LLDB.
1070-
BoolArgument<"IsLiteralLabel", /*optional=*/0, /*fake=*/1>
1071-
];
1062+
// Label specifies the mangled name for the decl.
1063+
StringArgument<"Label">, ];
10721064
let SemaHandler = 0;
10731065
let Documentation = [AsmLabelDocs];
1074-
let AdditionalMembers =
1075-
[{
1066+
let AdditionalMembers = [{
10761067
bool isEquivalent(AsmLabelAttr *Other) const {
1077-
return getLabel() == Other->getLabel() && getIsLiteralLabel() == Other->getIsLiteralLabel();
1068+
return getLabel() == Other->getLabel();
10781069
}
10791070
}];
10801071
}

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ def warn_drv_fraw_string_literals_in_cxx11 : Warning<
394394
"ignoring '-f%select{no-|}0raw-string-literals', which is only valid for C and C++ standards before C++11">,
395395
InGroup<UnusedCommandLineArgument>;
396396

397+
def err_drv_libclc_not_found : Error<"no libclc library '%0' found in the clang resource directory">;
398+
397399
def err_drv_invalid_malign_branch_EQ : Error<
398400
"invalid argument '%0' to -malign-branch=; each element must be one of: %1">;
399401

clang/include/clang/Driver/CommonArgs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ void addOpenMPDeviceRTL(const Driver &D, const llvm::opt::ArgList &DriverArgs,
215215
StringRef BitcodeSuffix, const llvm::Triple &Triple,
216216
const ToolChain &HostTC);
217217

218+
void addOpenCLBuiltinsLib(const Driver &D, const llvm::opt::ArgList &DriverArgs,
219+
llvm::opt::ArgStringList &CC1Args);
220+
218221
void addOutlineAtomicsArgs(const Driver &D, const ToolChain &TC,
219222
const llvm::opt::ArgList &Args,
220223
llvm::opt::ArgStringList &CmdArgs,

clang/include/clang/Driver/Options.td

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,21 @@ def fno_hip_emit_relocatable : Flag<["-"], "fno-hip-emit-relocatable">,
14221422
HelpText<"Do not override toolchain to compile HIP source to relocatable">;
14231423
}
14241424

1425+
// Clang specific/exclusive options for OpenACC.
1426+
def openacc_macro_override
1427+
: Separate<["-"], "fexperimental-openacc-macro-override">,
1428+
Visibility<[ClangOption, CC1Option]>,
1429+
Group<f_Group>,
1430+
HelpText<"Overrides the _OPENACC macro value for experimental testing "
1431+
"during OpenACC support development">;
1432+
def openacc_macro_override_EQ
1433+
: Joined<["-"], "fexperimental-openacc-macro-override=">,
1434+
Alias<openacc_macro_override>;
1435+
1436+
// End Clang specific/exclusive options for OpenACC.
1437+
1438+
def libclc_lib_EQ : Joined<["--"], "libclc-lib=">, Group<opencl_Group>,
1439+
HelpText<"Namespec of libclc OpenCL bitcode library to link">;
14251440
def libomptarget_amdgpu_bc_path_EQ : Joined<["--"], "libomptarget-amdgpu-bc-path=">, Group<i_Group>,
14261441
HelpText<"Path to libomptarget-amdgcn bitcode library">;
14271442
def libomptarget_amdgcn_bc_path_EQ : Joined<["--"], "libomptarget-amdgcn-bc-path=">, Group<i_Group>,

clang/include/clang/StaticAnalyzer/Checkers/Checkers.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ def StackAddrAsyncEscapeChecker
297297
"Check that addresses to stack memory do not escape the function">,
298298
Documentation<HasDocumentation>;
299299

300+
def StoreToImmutableChecker : Checker<"StoreToImmutable">,
301+
HelpText<"Check for writes to immutable memory regions. "
302+
"This implements part of SEI CERT Rule ENV30-C.">,
303+
Documentation<HasDocumentation>;
304+
300305
def PthreadLockBase : Checker<"PthreadLockBase">,
301306
HelpText<"Helper registering multiple checks.">,
302307
Documentation<NotDocumented>,

0 commit comments

Comments
 (0)