Skip to content

Commit f727748

Browse files
Merge branch 'main' into uint_to_fp
2 parents 25850f3 + 1332db3 commit f727748

File tree

62 files changed

+4182
-2275
lines changed

Some content is hidden

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

62 files changed

+4182
-2275
lines changed

clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ void UnhandledSelfAssignmentCheck::registerMatchers(MatchFinder *Finder) {
7474
// Matcher for standard smart pointers.
7575
const auto SmartPointerType = qualType(hasUnqualifiedDesugaredType(
7676
recordType(hasDeclaration(classTemplateSpecializationDecl(
77-
hasAnyName("::std::shared_ptr", "::std::unique_ptr",
78-
"::std::weak_ptr", "::std::auto_ptr"),
79-
templateArgumentCountIs(1))))));
77+
anyOf(allOf(hasAnyName("::std::shared_ptr", "::std::weak_ptr",
78+
"::std::auto_ptr"),
79+
templateArgumentCountIs(1)),
80+
allOf(hasName("::std::unique_ptr"),
81+
templateArgumentCountIs(2))))))));
8082

8183
// We will warn only if the class has a pointer or a C array field which
8284
// probably causes a problem during self-assignment (e.g. first resetting

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ Changes in existing checks
233233
`bsl::optional` and `bdlb::NullableValue` from
234234
<https://github.com/bloomberg/bde>_.
235235

236+
- Improved :doc:`bugprone-unhandled-self-assignment
237+
<clang-tidy/checks/bugprone/unhandled-self-assignment>` check by fixing smart
238+
pointer check against std::unique_ptr type.
239+
236240
- Improved :doc:`bugprone-unsafe-functions
237241
<clang-tidy/checks/bugprone/unsafe-functions>` check to allow specifying
238242
additional functions to match.

clang-tools-extra/test/clang-tidy/checkers/bugprone/unhandled-self-assignment.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ template <class T>
1010
T &&move(T &x) {
1111
}
1212

13-
template <class T>
13+
template <typename T> class default_delete {};
14+
15+
template <class T, typename Deleter = std::default_delete<T>>
1416
class unique_ptr {
1517
};
1618

clang/docs/ReleaseNotes.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,16 @@ Improvements to Clang's diagnostics
704704
return ptr + index < ptr; // warning
705705
}
706706
707+
- Clang now emits a ``-Wvarargs`` diagnostic when the second argument
708+
to ``va_arg`` is of array type, which is an undefined behavior (#GH119360).
709+
710+
.. code-block:: c++
711+
712+
void test() {
713+
va_list va;
714+
va_arg(va, int[10]); // warning
715+
}
716+
707717
- Fix -Wdangling false positives on conditional operators (#120206).
708718

709719
- Fixed a bug where Clang hung on an unsupported optional scope specifier ``::`` when parsing
@@ -754,6 +764,7 @@ Bug Fixes in This Version
754764
the unsupported type instead of the ``register`` keyword (#GH109776).
755765
- Fixed a crash when emit ctor for global variant with flexible array init (#GH113187).
756766
- Fixed a crash when GNU statement expression contains invalid statement (#GH113468).
767+
- Fixed a crash when passing the variable length array type to ``va_arg`` (#GH119360).
757768
- Fixed a failed assertion when using ``__attribute__((noderef))`` on an
758769
``_Atomic``-qualified type (#GH116124).
759770
- No longer return ``false`` for ``noexcept`` expressions involving a

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10512,6 +10512,10 @@ def warn_second_parameter_to_va_arg_ownership_qualified : Warning<
1051210512
def warn_second_parameter_to_va_arg_never_compatible : Warning<
1051310513
"second argument to 'va_arg' is of promotable type %0; this va_arg has "
1051410514
"undefined behavior because arguments will be promoted to %1">, InGroup<Varargs>;
10515+
def warn_second_parameter_to_va_arg_array : Warning<
10516+
"second argument to 'va_arg' is of array type %0; "
10517+
"this va_arg has undefined behavior because arguments "
10518+
"will never be compatible with array type">, InGroup<Varargs>;
1051510519

1051610520
def warn_return_missing_expr : Warning<
1051710521
"non-void %select{function|method}1 %0 should return a value">, DefaultError,

clang/lib/CodeGen/CGCall.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6090,6 +6090,8 @@ RValue CodeGenFunction::EmitVAArg(VAArgExpr *VE, Address &VAListAddr,
60906090
VAListAddr = VE->isMicrosoftABI() ? EmitMSVAListRef(VE->getSubExpr())
60916091
: EmitVAListRef(VE->getSubExpr());
60926092
QualType Ty = VE->getType();
6093+
if (Ty->isVariablyModifiedType())
6094+
EmitVariablyModifiedType(Ty);
60936095
if (VE->isMicrosoftABI())
60946096
return CGM.getABIInfo().EmitMSVAArg(*this, VAListAddr, Ty, Slot);
60956097
return CGM.getABIInfo().EmitVAArg(*this, VAListAddr, Ty, Slot);

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5448,11 +5448,6 @@ Value *ScalarExprEmitter::VisitChooseExpr(ChooseExpr *E) {
54485448
}
54495449

54505450
Value *ScalarExprEmitter::VisitVAArgExpr(VAArgExpr *VE) {
5451-
QualType Ty = VE->getType();
5452-
5453-
if (Ty->isVariablyModifiedType())
5454-
CGF.EmitVariablyModifiedType(Ty);
5455-
54565451
Address ArgValue = Address::invalid();
54575452
RValue ArgPtr = CGF.EmitVAArg(VE, ArgValue);
54585453

clang/lib/Sema/SemaExpr.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16592,6 +16592,13 @@ ExprResult Sema::BuildVAArgExpr(SourceLocation BuiltinLoc,
1659216592
<< TInfo->getTypeLoc().getSourceRange();
1659316593
}
1659416594

16595+
if (TInfo->getType()->isArrayType()) {
16596+
DiagRuntimeBehavior(TInfo->getTypeLoc().getBeginLoc(), E,
16597+
PDiag(diag::warn_second_parameter_to_va_arg_array)
16598+
<< TInfo->getType()
16599+
<< TInfo->getTypeLoc().getSourceRange());
16600+
}
16601+
1659516602
// Check for va_arg where arguments of the given type will be promoted
1659616603
// (i.e. this va_arg is guaranteed to have undefined behavior).
1659716604
QualType PromoteType;

clang/test/CodeGen/xcore-abi.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ void testva (int n, ...) {
7676
// CHECK: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[V5]], ptr align 4 [[P]], i32 20, i1 false)
7777
// CHECK: call void @f(ptr noundef [[V5]])
7878

79-
int* v6 = va_arg (ap, int[4]); // an unusual aggregate type
79+
// an unusual aggregate type
80+
int* v6 = va_arg (ap, int[4]); // expected-warning{{second argument to 'va_arg' is of array type 'int[4]'}}
8081
f(v6);
8182
// CHECK: [[I:%[a-z0-9]+]] = load ptr, ptr [[AP]]
8283
// CHECK: [[P:%[a-z0-9]+]] = load ptr, ptr [[I]]

clang/test/Driver/spirv-openmp-toolchain.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fopenmp -fopenmp-targets=spirv64-intel \
1+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp -fopenmp-targets=spirv64-intel \
22
// RUN: --libomptarget-spirv-bc-path=%t/ -nogpulib %s 2>&1 \
33
// RUN: | FileCheck %s
44

0 commit comments

Comments
 (0)