Skip to content

Commit 45c8527

Browse files
committed
Merge from 'main' to 'sycl-web' (54 commits)
CONFLICT (content): Merge conflict in clang/lib/CodeGen/CodeGenModule.h CONFLICT (content): Merge conflict in clang/lib/CodeGen/CodeGenModule.cpp
2 parents 612566a + 73417c5 commit 45c8527

File tree

169 files changed

+4949
-1381
lines changed

Some content is hidden

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

169 files changed

+4949
-1381
lines changed

clang-tools-extra/clangd/ParsedAST.cpp

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,69 @@ class ReplayPreamble : private PPCallbacks {
233233
std::vector<syntax::Token> MainFileTokens;
234234
};
235235

236+
// Filter for clang diagnostics groups enabled by CTOptions.Checks.
237+
//
238+
// These are check names like clang-diagnostics-unused.
239+
// Note that unlike -Wunused, clang-diagnostics-unused does not imply
240+
// subcategories like clang-diagnostics-unused-function.
241+
//
242+
// This is used to determine which diagnostics can be enabled by ExtraArgs in
243+
// the clang-tidy configuration.
244+
class TidyDiagnosticGroups {
245+
// Whether all diagnostic groups are enabled by default.
246+
// True if we've seen clang-diagnostic-*.
247+
bool Default = false;
248+
// Set of diag::Group whose enablement != Default.
249+
// If Default is false, this is foo where we've seen clang-diagnostic-foo.
250+
llvm::DenseSet<unsigned> Exceptions;
251+
252+
public:
253+
TidyDiagnosticGroups(llvm::StringRef Checks) {
254+
constexpr llvm::StringLiteral CDPrefix = "clang-diagnostic-";
255+
256+
llvm::StringRef Check;
257+
while (!Checks.empty()) {
258+
std::tie(Check, Checks) = Checks.split(',');
259+
if (Check.empty())
260+
continue;
261+
262+
bool Enable = !Check.consume_front("-");
263+
bool Glob = Check.consume_back("*");
264+
if (Glob) {
265+
// Is this clang-diagnostic-*, or *, or so?
266+
// (We ignore all other types of globs).
267+
if (CDPrefix.startswith(Check)) {
268+
Default = Enable;
269+
Exceptions.clear();
270+
}
271+
continue;
272+
}
273+
274+
// In "*,clang-diagnostic-foo", the latter is a no-op.
275+
if (Default == Enable)
276+
continue;
277+
// The only non-glob entries we care about are clang-diagnostic-foo.
278+
if (!Check.consume_front(CDPrefix))
279+
continue;
280+
281+
if (auto Group = DiagnosticIDs::getGroupForWarningOption(Check))
282+
Exceptions.insert(static_cast<unsigned>(*Group));
283+
}
284+
}
285+
286+
bool operator()(diag::Group GroupID) const {
287+
return Exceptions.contains(static_cast<unsigned>(GroupID)) ? !Default
288+
: Default;
289+
}
290+
};
291+
236292
// Find -W<group> and -Wno-<group> options in ExtraArgs and apply them to Diags.
237293
//
238294
// This is used to handle ExtraArgs in clang-tidy configuration.
239295
// We don't use clang's standard handling of this as we want slightly different
240296
// behavior (e.g. we want to exclude these from -Wno-error).
241297
void applyWarningOptions(llvm::ArrayRef<std::string> ExtraArgs,
298+
llvm::function_ref<bool(diag::Group)> EnabledGroups,
242299
DiagnosticsEngine &Diags) {
243300
for (llvm::StringRef Group : ExtraArgs) {
244301
// Only handle args that are of the form -W[no-]<group>.
@@ -259,6 +316,9 @@ void applyWarningOptions(llvm::ArrayRef<std::string> ExtraArgs,
259316
if (Enable) {
260317
if (Diags.getDiagnosticLevel(ID, SourceLocation()) <
261318
DiagnosticsEngine::Warning) {
319+
auto Group = DiagnosticIDs::getGroupForDiag(ID);
320+
if (!Group || !EnabledGroups(*Group))
321+
continue;
262322
Diags.setSeverity(ID, diag::Severity::Warning, SourceLocation());
263323
if (Diags.getWarningsAsErrors())
264324
NeedsWerrorExclusion = true;
@@ -354,18 +414,25 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
354414
// - ExtraArgs: ["-Wfoo"] causes clang to produce the warnings
355415
// - Checks: "clang-diagnostic-foo" prevents clang-tidy filtering them out
356416
//
357-
// We treat these as clang warnings, so the Checks part is not relevant.
358-
// We must enable the warnings specified in ExtraArgs.
417+
// In clang-tidy, diagnostics are emitted if they pass both checks.
418+
// When groups contain subgroups, -Wparent includes the child, but
419+
// clang-diagnostic-parent does not.
359420
//
360-
// We *don't* want to change the compile command directly. this can have
421+
// We *don't* want to change the compile command directly. This can have
361422
// too many unexpected effects: breaking the command, interactions with
362423
// -- and -Werror, etc. Besides, we've already parsed the command.
363424
// Instead we parse the -W<group> flags and handle them directly.
425+
//
426+
// Similarly, we don't want to use Checks to filter clang diagnostics after
427+
// they are generated, as this spreads clang-tidy emulation everywhere.
428+
// Instead, we just use these to filter which extra diagnostics we enable.
364429
auto &Diags = Clang->getDiagnostics();
430+
TidyDiagnosticGroups TidyGroups(ClangTidyOpts.Checks ? *ClangTidyOpts.Checks
431+
: llvm::StringRef());
365432
if (ClangTidyOpts.ExtraArgsBefore)
366-
applyWarningOptions(*ClangTidyOpts.ExtraArgsBefore, Diags);
433+
applyWarningOptions(*ClangTidyOpts.ExtraArgsBefore, TidyGroups, Diags);
367434
if (ClangTidyOpts.ExtraArgs)
368-
applyWarningOptions(*ClangTidyOpts.ExtraArgs, Diags);
435+
applyWarningOptions(*ClangTidyOpts.ExtraArgs, TidyGroups, Diags);
369436
} else {
370437
// Skips some analysis.
371438
Clang->getDiagnosticOpts().IgnoreWarnings = true;

clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -517,13 +517,16 @@ TEST(DiagnosticTest, ClangTidyWarningAsError) {
517517
diagSeverity(DiagnosticsEngine::Error)))));
518518
}
519519

520-
TidyProvider addClangArgs(std::vector<llvm::StringRef> ExtraArgs) {
521-
return [ExtraArgs = std::move(ExtraArgs)](tidy::ClangTidyOptions &Opts,
522-
llvm::StringRef) {
520+
TidyProvider addClangArgs(std::vector<llvm::StringRef> ExtraArgs,
521+
llvm::StringRef Checks) {
522+
return [ExtraArgs = std::move(ExtraArgs), Checks = Checks.str()](
523+
tidy::ClangTidyOptions &Opts, llvm::StringRef) {
523524
if (!Opts.ExtraArgs)
524525
Opts.ExtraArgs.emplace();
525526
for (llvm::StringRef Arg : ExtraArgs)
526527
Opts.ExtraArgs->emplace_back(Arg);
528+
if (!Checks.empty())
529+
Opts.Checks = Checks;
527530
};
528531
}
529532

@@ -541,53 +544,78 @@ TEST(DiagnosticTest, ClangTidyEnablesClangWarning) {
541544
// Check the -Wunused warning isn't initially on.
542545
EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());
543546

544-
// We enable warnings based on clang-tidy extra args.
545-
TU.ClangTidyProvider = addClangArgs({"-Wunused"});
547+
// We enable warnings based on clang-tidy extra args, if the matching
548+
// clang-diagnostic- is there.
549+
TU.ClangTidyProvider =
550+
addClangArgs({"-Wunused"}, "clang-diagnostic-unused-function");
551+
EXPECT_THAT(*TU.build().getDiagnostics(), ElementsAre(UnusedFooWarning));
552+
553+
// clang-diagnostic-* is acceptable
554+
TU.ClangTidyProvider = addClangArgs({"-Wunused"}, "clang-diagnostic-*");
546555
EXPECT_THAT(*TU.build().getDiagnostics(), ElementsAre(UnusedFooWarning));
556+
// And plain *
557+
TU.ClangTidyProvider = addClangArgs({"-Wunused"}, "*");
558+
EXPECT_THAT(*TU.build().getDiagnostics(), ElementsAre(UnusedFooWarning));
559+
// And we can explicitly exclude a category too.
560+
TU.ClangTidyProvider =
561+
addClangArgs({"-Wunused"}, "*,-clang-diagnostic-unused-function");
562+
EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());
547563

548-
// But we don't respect other args.
549-
TU.ClangTidyProvider = addClangArgs({"-Wunused", "-Dfoo=bar"});
564+
// Without the exact check specified, the warnings are not enabled.
565+
TU.ClangTidyProvider = addClangArgs({"-Wunused"}, "clang-diagnostic-unused");
566+
EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());
567+
568+
// We don't respect other args.
569+
TU.ClangTidyProvider = addClangArgs({"-Wunused", "-Dfoo=bar"},
570+
"clang-diagnostic-unused-function");
550571
EXPECT_THAT(*TU.build().getDiagnostics(), ElementsAre(UnusedFooWarning))
551572
<< "Not unused function 'bar'!";
552573

553574
// -Werror doesn't apply to warnings enabled by clang-tidy extra args.
554575
TU.ExtraArgs = {"-Werror"};
555-
TU.ClangTidyProvider = addClangArgs({"-Wunused"});
576+
TU.ClangTidyProvider =
577+
addClangArgs({"-Wunused"}, "clang-diagnostic-unused-function");
556578
EXPECT_THAT(*TU.build().getDiagnostics(),
557579
ElementsAre(diagSeverity(DiagnosticsEngine::Warning)));
558580

559581
// But clang-tidy extra args won't *downgrade* errors to warnings either.
560582
TU.ExtraArgs = {"-Wunused", "-Werror"};
561-
TU.ClangTidyProvider = addClangArgs({"-Wunused"});
583+
TU.ClangTidyProvider =
584+
addClangArgs({"-Wunused"}, "clang-diagnostic-unused-function");
562585
EXPECT_THAT(*TU.build().getDiagnostics(),
563586
ElementsAre(diagSeverity(DiagnosticsEngine::Error)));
564587

565588
// FIXME: we're erroneously downgrading the whole group, this should be Error.
566589
TU.ExtraArgs = {"-Wunused-function", "-Werror"};
567-
TU.ClangTidyProvider = addClangArgs({"-Wunused"});
590+
TU.ClangTidyProvider =
591+
addClangArgs({"-Wunused"}, "clang-diagnostic-unused-label");
568592
EXPECT_THAT(*TU.build().getDiagnostics(),
569593
ElementsAre(diagSeverity(DiagnosticsEngine::Warning)));
570594

571595
// This looks silly, but it's the typical result if a warning is enabled by a
572596
// high-level .clang-tidy file and disabled by a low-level one.
573597
TU.ExtraArgs = {};
574-
TU.ClangTidyProvider = addClangArgs({"-Wunused", "-Wno-unused"});
598+
TU.ClangTidyProvider = addClangArgs({"-Wunused", "-Wno-unused"},
599+
"clang-diagnostic-unused-function");
575600
EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());
576601

577602
// Overriding only works in the proper order.
578-
TU.ClangTidyProvider = addClangArgs({"-Wno-unused", "-Wunused"});
603+
TU.ClangTidyProvider =
604+
addClangArgs({"-Wunused"}, {"clang-diagnostic-unused-function"});
579605
EXPECT_THAT(*TU.build().getDiagnostics(), SizeIs(1));
580606

581607
// More specific vs less-specific: match clang behavior
582-
TU.ClangTidyProvider = addClangArgs({"-Wunused", "-Wno-unused-function"});
608+
TU.ClangTidyProvider = addClangArgs({"-Wunused", "-Wno-unused-function"},
609+
{"clang-diagnostic-unused-function"});
583610
EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());
584-
TU.ClangTidyProvider = addClangArgs({"-Wunused-function", "-Wno-unused"});
611+
TU.ClangTidyProvider = addClangArgs({"-Wunused-function", "-Wno-unused"},
612+
{"clang-diagnostic-unused-function"});
585613
EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());
586614

587-
// We do allow clang-tidy config to disable warnings from the compile command.
588-
// It's unclear this is ideal, but it's hard to avoid.
615+
// We do allow clang-tidy config to disable warnings from the compile
616+
// command. It's unclear this is ideal, but it's hard to avoid.
589617
TU.ExtraArgs = {"-Wunused"};
590-
TU.ClangTidyProvider = addClangArgs({"-Wno-unused"});
618+
TU.ClangTidyProvider = addClangArgs({"-Wno-unused"}, {});
591619
EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty());
592620
}
593621

clang/docs/ClangCommandLineReference.rst

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,22 @@ Flush denormal floating point values to zero in CUDA/HIP device mode.
238238

239239
Specify comma-separated list of triples OpenMP offloading targets to be supported
240240

241+
.. option:: -fopenmp-new-driver, -fno-openmp-new-driver
242+
243+
Use the new driver for OpenMP offloading.
244+
245+
.. option:: --offload-new-driver, --no-offload-new-driver
246+
247+
Use the new driver for offloading compilation.
248+
249+
.. option:: --offload-host-only
250+
251+
Only compile for the host when offloading.
252+
253+
.. option:: --offload-device-only
254+
255+
Only compile for the device when offloading.
256+
241257
.. option:: -force\_cpusubtype\_ALL
242258

243259
.. program:: clang1
@@ -801,10 +817,6 @@ Generate Interface Stub Files, emit merged text not binary.
801817

802818
Extract API information
803819

804-
.. option:: -fopenmp-new-driver, fno-openmp-new-driver
805-
806-
Use the new driver for OpenMP offloading.
807-
808820
.. option:: -fsyntax-only
809821

810822
.. option:: -module-file-info

clang/docs/ReleaseNotes.rst

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,17 @@ Improvements to Clang's diagnostics
149149
now only diagnose deprecated declarations and definitions of functions
150150
without a prototype where the behavior in C2x will remain correct. This
151151
diagnostic remains off by default but is now enabled via ``-pedantic`` due to
152-
it being a deprecation warning. ``-Wdeprecated-non-prototype`` will diagnose
153-
cases where the deprecated declarations or definitions of a function without
154-
a prototype will change behavior in C2x. Additionally, it will diagnose calls
155-
which pass arguments to a function without a prototype. This warning is
156-
enabled only when the ``-Wdeprecated-non-prototype`` option is enabled at the
157-
function declaration site, which allows a developer to disable the diagnostic
158-
for all callers at the point of declaration. This diagnostic is grouped under
159-
the ``-Wstrict-prototypes`` warning group, but is enabled by default.
152+
it being a deprecation warning. ``-Wstrict-prototypes`` has no effect in C2x
153+
or when ``-fno-knr-functions`` is enabled. ``-Wdeprecated-non-prototype``
154+
will diagnose cases where the deprecated declarations or definitions of a
155+
function without a prototype will change behavior in C2x. Additionally, it
156+
will diagnose calls which pass arguments to a function without a prototype.
157+
This warning is enabled only when the ``-Wdeprecated-non-prototype`` option
158+
is enabled at the function declaration site, which allows a developer to
159+
disable the diagnostic for all callers at the point of declaration. This
160+
diagnostic is grouped under the ``-Wstrict-prototypes`` warning group, but is
161+
enabled by default. ``-Wdeprecated-non-prototype`` has no effect in C2x or
162+
when ``-fno-knr-functions`` is enabled.
160163
- Clang now appropriately issues an error in C when a definition of a function
161164
without a prototype and with no arguments is an invalid redeclaration of a
162165
function with a prototype. e.g., ``void f(int); void f() {}`` is now properly

clang/include/clang/Analysis/Analyses/ThreadSafety.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,8 @@ class ThreadSafetyHandler {
9898
virtual ~ThreadSafetyHandler();
9999

100100
/// Warn about lock expressions which fail to resolve to lockable objects.
101-
/// \param Kind -- the capability's name parameter (role, mutex, etc).
102101
/// \param Loc -- the SourceLocation of the unresolved expression.
103-
virtual void handleInvalidLockExp(StringRef Kind, SourceLocation Loc) {}
102+
virtual void handleInvalidLockExp(SourceLocation Loc) {}
104103

105104
/// Warn about unlock function calls that do not have a prior matching lock
106105
/// expression.
@@ -169,14 +168,12 @@ class ThreadSafetyHandler {
169168
SourceLocation Loc2) {}
170169

171170
/// Warn when a protected operation occurs while no locks are held.
172-
/// \param Kind -- the capability's name parameter (role, mutex, etc).
173171
/// \param D -- The decl for the protected variable or function
174172
/// \param POK -- The kind of protected operation (e.g. variable access)
175173
/// \param AK -- The kind of access (i.e. read or write) that occurred
176174
/// \param Loc -- The location of the protected operation.
177-
virtual void handleNoMutexHeld(StringRef Kind, const NamedDecl *D,
178-
ProtectedOperationKind POK, AccessKind AK,
179-
SourceLocation Loc) {}
175+
virtual void handleNoMutexHeld(const NamedDecl *D, ProtectedOperationKind POK,
176+
AccessKind AK, SourceLocation Loc) {}
180177

181178
/// Warn when a protected operation occurs while the specific mutex protecting
182179
/// the operation is not locked.

0 commit comments

Comments
 (0)