[clang] 284bf51 - [clang][analyzer] Add support for detecting uninitialized dynamically-allocated objects
via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 29 02:25:18 PDT 2026
Author: guillem-bartrina-sonarsource
Date: 2026-04-29T11:25:13+02:00
New Revision: 284bf515feecd0c62adf1f318332b35ed8861c93
URL: https://github.com/llvm/llvm-project/commit/284bf515feecd0c62adf1f318332b35ed8861c93
DIFF: https://github.com/llvm/llvm-project/commit/284bf515feecd0c62adf1f318332b35ed8861c93.diff
LOG: [clang][analyzer] Add support for detecting uninitialized dynamically-allocated objects
Adapt the allocated region into a `TypedValueRegion` by retrieving its
type and wrapping it in an `ElementRegion`.
The `willObjectBeAnalyzedLater` function must therefore fall back on
using `SubRegion`s.
CPP-7677
Added:
Modified:
clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
clang/test/Analysis/cxx-uninitialized-object-inheritance.cpp
clang/test/Analysis/cxx-uninitialized-object-no-dereference.cpp
clang/test/Analysis/cxx-uninitialized-object-notes-as-warnings.cpp
clang/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
clang/test/Analysis/cxx-uninitialized-object-unguarded-access.cpp
clang/test/Analysis/cxx-uninitialized-object-unionlike-constructs.cpp
clang/test/Analysis/cxx-uninitialized-object.cpp
clang/test/Analysis/objcpp-uninitialized-object.mm
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
index 6d4389fda8753..4fd858650204c 100644
--- a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -451,26 +451,44 @@ static void printTail(llvm::raw_ostream &Out,
// Utility functions.
//===----------------------------------------------------------------------===//
+static const SubRegion *
+getConstructedSubRegion(const CXXConstructorDecl *CtorDecl,
+ CheckerContext &Context) {
+ Loc ThisLoc =
+ Context.getSValBuilder().getCXXThis(CtorDecl, Context.getStackFrame());
+ SVal ObjectV = Context.getState()->getSVal(ThisLoc);
+ return ObjectV.getAsRegion()->getAs<SubRegion>();
+}
+
static const TypedValueRegion *
getConstructedRegion(const CXXConstructorDecl *CtorDecl,
CheckerContext &Context) {
- Loc ThisLoc =
- Context.getSValBuilder().getCXXThis(CtorDecl, Context.getStackFrame());
+ const SubRegion *SR = getConstructedSubRegion(CtorDecl, Context);
+ if (!SR)
+ return nullptr;
- SVal ObjectV = Context.getState()->getSVal(ThisLoc);
+ if (const auto *TVR = SR->getAs<TypedValueRegion>()) {
+ return TVR->getValueType()->getAsCXXRecordDecl() ? TVR : nullptr;
+ }
- auto *R = ObjectV.getAsRegion()->getAs<TypedValueRegion>();
- if (R && !R->getValueType()->getAsCXXRecordDecl())
+ QualType ThisPointeeTy = CtorDecl->getThisType()->getPointeeType();
+ if (!ThisPointeeTy->getAsCXXRecordDecl())
return nullptr;
- return R;
+ auto &MemMgr = Context.getState()->getStateManager().getRegionManager();
+ auto &SVB = Context.getSValBuilder();
+
+ const auto *ElemR = MemMgr.getElementRegion(
+ ThisPointeeTy, SVB.makeZeroArrayIndex(), SR, Context.getASTContext());
+
+ return ElemR;
}
static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor,
CheckerContext &Context) {
- const TypedValueRegion *CurrRegion = getConstructedRegion(Ctor, Context);
+ const SubRegion *CurrRegion = getConstructedSubRegion(Ctor, Context);
if (!CurrRegion)
return false;
@@ -482,8 +500,7 @@ static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor,
if (!OtherCtor)
continue;
- const TypedValueRegion *OtherRegion =
- getConstructedRegion(OtherCtor, Context);
+ const SubRegion *OtherRegion = getConstructedSubRegion(OtherCtor, Context);
if (!OtherRegion)
continue;
diff --git a/clang/test/Analysis/cxx-uninitialized-object-inheritance.cpp b/clang/test/Analysis/cxx-uninitialized-object-inheritance.cpp
index e2d190daaaa94..f5b605910b4cc 100644
--- a/clang/test/Analysis/cxx-uninitialized-object-inheritance.cpp
+++ b/clang/test/Analysis/cxx-uninitialized-object-inheritance.cpp
@@ -2,6 +2,16 @@
// RUN: -analyzer-config optin.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \
// RUN: -analyzer-config optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true \
// RUN: -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.UninitializedObject \
+// RUN: -analyzer-config optin.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \
+// RUN: -analyzer-config optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true \
+// RUN: -std=c++11 -verify %s -DHEAP_ALLOCATION
+
+#ifdef HEAP_ALLOCATION
+#define INIT(CLS, ARGS) new CLS ARGS
+#else
+#define INIT(CLS, ARGS) (void) CLS ARGS
+#endif
//===----------------------------------------------------------------------===//
// Non-polymorphic inheritance tests
@@ -31,7 +41,7 @@ class NonPolymorphicInheritanceTest1 : public NonPolymorphicLeft1 {
};
void fNonPolymorphicInheritanceTest1() {
- NonPolymorphicInheritanceTest1();
+ INIT(NonPolymorphicInheritanceTest1, ());
}
class NonPolymorphicBaseClass2 {
@@ -55,7 +65,7 @@ class NonPolymorphicInheritanceTest2 : public NonPolymorphicBaseClass2 {
};
void fNonPolymorphicInheritanceTest2() {
- NonPolymorphicInheritanceTest2();
+ INIT(NonPolymorphicInheritanceTest2, ());
}
class NonPolymorphicBaseClass3 {
@@ -79,7 +89,7 @@ class NonPolymorphicInheritanceTest3 : public NonPolymorphicBaseClass3 {
};
void fNonPolymorphicInheritanceTest3() {
- NonPolymorphicInheritanceTest3();
+ INIT(NonPolymorphicInheritanceTest3, ());
}
class NonPolymorphicBaseClass4 {
@@ -104,7 +114,7 @@ class NonPolymorphicInheritanceTest4 : public NonPolymorphicBaseClass4 {
};
void fNonPolymorphicInheritanceTest4() {
- NonPolymorphicInheritanceTest4();
+ INIT(NonPolymorphicInheritanceTest4, ());
}
//===----------------------------------------------------------------------===//
@@ -136,7 +146,7 @@ class PolymorphicInheritanceTest1 : public PolymorphicLeft1 {
};
void fPolymorphicInheritanceTest1() {
- PolymorphicInheritanceTest1();
+ INIT(PolymorphicInheritanceTest1, ());
}
class PolymorphicRight1 {
@@ -161,7 +171,7 @@ class PolymorphicInheritanceTest2 : public PolymorphicRight1 {
};
void fPolymorphicInheritanceTest2() {
- PolymorphicInheritanceTest2();
+ INIT(PolymorphicInheritanceTest2, ());
}
class PolymorphicBaseClass3 {
@@ -186,7 +196,7 @@ class PolymorphicInheritanceTest3 : public PolymorphicBaseClass3 {
};
void fPolymorphicInheritanceTest3() {
- PolymorphicInheritanceTest3();
+ INIT(PolymorphicInheritanceTest3, ());
}
class PolymorphicBaseClass4 {
@@ -212,7 +222,7 @@ class PolymorphicInheritanceTest4 : public PolymorphicBaseClass4 {
};
void fPolymorphicInheritanceTest4() {
- PolymorphicInheritanceTest4();
+ INIT(PolymorphicInheritanceTest4, ());
}
//===----------------------------------------------------------------------===//
@@ -244,7 +254,7 @@ class VirtualInheritanceTest1 : virtual public VirtualPolymorphicLeft1 {
};
void fVirtualInheritanceTest1() {
- VirtualInheritanceTest1();
+ INIT(VirtualInheritanceTest1, ());
}
class VirtualPolymorphicRight1 {
@@ -269,7 +279,7 @@ class VirtualInheritanceTest2 : virtual public VirtualPolymorphicRight1 {
};
void fVirtualInheritanceTest2() {
- VirtualInheritanceTest2();
+ INIT(VirtualInheritanceTest2, ());
}
class VirtualPolymorphicBaseClass3 {
@@ -294,7 +304,7 @@ class VirtualInheritanceTest3 : virtual public VirtualPolymorphicBaseClass3 {
};
void fVirtualInheritanceTest3() {
- VirtualInheritanceTest3();
+ INIT(VirtualInheritanceTest3, ());
}
//===----------------------------------------------------------------------===//
@@ -347,9 +357,9 @@ class MultipleInheritanceTest1 : public Left1, public Right1 {
};
void fMultipleInheritanceTest1() {
- MultipleInheritanceTest1();
- MultipleInheritanceTest1(int());
- MultipleInheritanceTest1(int(), int());
+ INIT(MultipleInheritanceTest1, ());
+ INIT(MultipleInheritanceTest1, (int()));
+ INIT(MultipleInheritanceTest1, (int(), int()));
}
struct Left2 {
@@ -374,7 +384,7 @@ class MultipleInheritanceTest2 : public Left2, public Right2 {
};
void fMultipleInheritanceTest2() {
- MultipleInheritanceTest2();
+ INIT(MultipleInheritanceTest2, ());
}
struct Left3 {
@@ -399,7 +409,7 @@ class MultipleInheritanceTest3 : public Left3, public Right3 {
};
void fMultipleInheritanceTest3() {
- MultipleInheritanceTest3();
+ INIT(MultipleInheritanceTest3, ());
}
struct Left4 {
@@ -424,7 +434,7 @@ class MultipleInheritanceTest4 : public Left4, public Right4 {
};
void fMultipleInheritanceTest4() {
- MultipleInheritanceTest4();
+ INIT(MultipleInheritanceTest4, ());
}
struct Left5 {
@@ -448,7 +458,7 @@ class MultipleInheritanceTest5 : public Left5, public Right5 {
};
void fMultipleInheritanceTest5() {
- MultipleInheritanceTest5();
+ INIT(MultipleInheritanceTest5, ());
}
//===----------------------------------------------------------------------===//
@@ -508,9 +518,9 @@ class NonVirtualDiamondInheritanceTest1 : public First1, public Second1 {
};
void fNonVirtualDiamondInheritanceTest1() {
- NonVirtualDiamondInheritanceTest1();
- NonVirtualDiamondInheritanceTest1(int());
- NonVirtualDiamondInheritanceTest1(int(), int());
+ INIT(NonVirtualDiamondInheritanceTest1, ());
+ INIT(NonVirtualDiamondInheritanceTest1, (int()));
+ INIT(NonVirtualDiamondInheritanceTest1, (int(), int()));
}
struct NonVirtualBase2 {
@@ -538,7 +548,7 @@ class NonVirtualDiamondInheritanceTest2 : public First2, public Second2 {
};
void fNonVirtualDiamondInheritanceTest2() {
- NonVirtualDiamondInheritanceTest2();
+ INIT(NonVirtualDiamondInheritanceTest2, ());
}
struct NonVirtualBase3 {
@@ -566,7 +576,7 @@ class NonVirtualDiamondInheritanceTest3 : public First3, public Second3 {
};
void fNonVirtualDiamondInheritanceTest3() {
- NonVirtualDiamondInheritanceTest3();
+ INIT(NonVirtualDiamondInheritanceTest3, ());
}
struct NonVirtualBase4 {
@@ -594,7 +604,7 @@ class NonVirtualDiamondInheritanceTest4 : public First4, public Second4 {
};
void fNonVirtualDiamondInheritanceTest4() {
- NonVirtualDiamondInheritanceTest4();
+ INIT(NonVirtualDiamondInheritanceTest4, ());
}
struct NonVirtualBase5 {
@@ -622,7 +632,7 @@ class NonVirtualDiamondInheritanceTest5 : public First5, public Second5 {
};
void fNonVirtualDiamondInheritanceTest5() {
- NonVirtualDiamondInheritanceTest5();
+ INIT(NonVirtualDiamondInheritanceTest5, ());
}
struct NonVirtualBase6 {
@@ -650,7 +660,7 @@ class NonVirtualDiamondInheritanceTest6 : public First6, public Second6 {
};
void fNonVirtualDiamondInheritanceTest6() {
- NonVirtualDiamondInheritanceTest6();
+ INIT(NonVirtualDiamondInheritanceTest6, ());
}
//===----------------------------------------------------------------------===//
@@ -706,9 +716,9 @@ class VirtualDiamondInheritanceTest1 : public VirtualFirst1, public VirtualSecon
};
void fVirtualDiamondInheritanceTest1() {
- VirtualDiamondInheritanceTest1();
- VirtualDiamondInheritanceTest1(int());
- VirtualDiamondInheritanceTest1(int(), int());
+ INIT(VirtualDiamondInheritanceTest1, ());
+ INIT(VirtualDiamondInheritanceTest1, (int()));
+ INIT(VirtualDiamondInheritanceTest1, (int(), int()));
}
struct VirtualBase2 {
@@ -747,7 +757,7 @@ class VirtualDiamondInheritanceTest2 : public VirtualFirst2, public VirtualSecon
};
void fVirtualDiamondInheritanceTest2() {
- VirtualDiamondInheritanceTest2();
+ INIT(VirtualDiamondInheritanceTest2, ());
}
struct VirtualBase3 {
@@ -774,7 +784,7 @@ class VirtualDiamondInheritanceTest3 : public VirtualFirst3, public VirtualSecon
};
void fVirtualDiamondInheritanceTest3() {
- VirtualDiamondInheritanceTest3();
+ INIT(VirtualDiamondInheritanceTest3, ());
}
//===----------------------------------------------------------------------===//
@@ -795,7 +805,7 @@ struct DynamicTypeTest1 {
void fDynamicTypeTest1() {
DynTDerived1 d;
- DynamicTypeTest1 t(&d);
+ INIT(DynamicTypeTest1, (&d));
};
struct DynTBase2 {
@@ -814,7 +824,7 @@ struct DynamicTypeTest2 {
void fDynamicTypeTest2() {
DynTDerived2 d;
- DynamicTypeTest2 t(&d);
+ INIT(DynamicTypeTest2, (&d));
}
struct SymbolicSuperRegionBase {
@@ -829,5 +839,5 @@ struct SymbolicSuperRegionDerived : SymbolicSuperRegionBase {
SymbolicSuperRegionDerived *getSymbolicRegion();
void fSymbolicSuperRegionTest() {
- SymbolicSuperRegionDerived test(getSymbolicRegion());
+ INIT(SymbolicSuperRegionDerived, (getSymbolicRegion()));
}
diff --git a/clang/test/Analysis/cxx-uninitialized-object-no-dereference.cpp b/clang/test/Analysis/cxx-uninitialized-object-no-dereference.cpp
index e0aafb98085f2..17f7f910cd3e3 100644
--- a/clang/test/Analysis/cxx-uninitialized-object-no-dereference.cpp
+++ b/clang/test/Analysis/cxx-uninitialized-object-no-dereference.cpp
@@ -1,5 +1,13 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.UninitializedObject \
// RUN: -std=c++11 -DPEDANTIC -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.UninitializedObject \
+// RUN: -std=c++11 -DPEDANTIC -verify %s -DHEAP_ALLOCATION
+
+#ifdef HEAP_ALLOCATION
+#define INIT(CLS, ARGS) new CLS ARGS
+#else
+#define INIT(CLS, ARGS) (void) CLS ARGS
+#endif
class UninitPointerTest {
int *ptr; // expected-note{{uninitialized pointer 'this->ptr'}}
@@ -10,7 +18,7 @@ class UninitPointerTest {
};
void fUninitPointerTest() {
- UninitPointerTest();
+ INIT(UninitPointerTest, ());
}
class UninitPointeeTest {
@@ -23,5 +31,5 @@ class UninitPointeeTest {
void fUninitPointeeTest() {
int a;
- UninitPointeeTest t(&a);
+ INIT(UninitPointeeTest, (&a));
}
diff --git a/clang/test/Analysis/cxx-uninitialized-object-notes-as-warnings.cpp b/clang/test/Analysis/cxx-uninitialized-object-notes-as-warnings.cpp
index 33f7b0dba07e2..56e1b56bc11fd 100644
--- a/clang/test/Analysis/cxx-uninitialized-object-notes-as-warnings.cpp
+++ b/clang/test/Analysis/cxx-uninitialized-object-notes-as-warnings.cpp
@@ -2,6 +2,16 @@
// RUN: -analyzer-config optin.cplusplus.UninitializedObject:NotesAsWarnings=true \
// RUN: -analyzer-config optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true \
// RUN: -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.UninitializedObject \
+// RUN: -analyzer-config optin.cplusplus.UninitializedObject:NotesAsWarnings=true \
+// RUN: -analyzer-config optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true \
+// RUN: -std=c++11 -verify %s -DHEAP_ALLOCATION
+
+#ifdef HEAP_ALLOCATION
+#define INIT(CLS, ARGS) new CLS ARGS
+#else
+#define INIT(CLS, ARGS) (void) CLS ARGS
+#endif
class NotesAsWarningsTest {
int a;
@@ -14,5 +24,5 @@ class NotesAsWarningsTest {
};
void fNotesAsWarningsTest() {
- NotesAsWarningsTest();
+ INIT(NotesAsWarningsTest, ());
}
diff --git a/clang/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp b/clang/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
index d0eb9e80d6395..fddd6c8c3d6df 100644
--- a/clang/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
+++ b/clang/test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
@@ -2,10 +2,23 @@
// RUN: -analyzer-config optin.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \
// RUN: -analyzer-config optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true \
// RUN: -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc,optin.cplusplus.UninitializedObject \
+// RUN: -analyzer-config optin.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \
+// RUN: -analyzer-config optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true \
+// RUN: -std=c++11 -verify %s -DHEAP_ALLOCATION
// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc,optin.cplusplus.UninitializedObject \
// RUN: -analyzer-config optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true \
// RUN: -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc,optin.cplusplus.UninitializedObject \
+// RUN: -analyzer-config optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true \
+// RUN: -std=c++11 -verify %s -DHEAP_ALLOCATION
+
+#ifdef HEAP_ALLOCATION
+#define INIT(CLS, ARGS) new CLS ARGS
+#else
+#define INIT(CLS, ARGS) (void) CLS ARGS
+#endif
//===----------------------------------------------------------------------===//
// Concrete location tests.
@@ -18,7 +31,7 @@ struct ConcreteIntLocTest {
};
void fConcreteIntLocTest() {
- ConcreteIntLocTest();
+ INIT(ConcreteIntLocTest, ());
}
//===----------------------------------------------------------------------===//
@@ -36,7 +49,7 @@ struct LocAsIntegerTest {
void fLocAsIntegerTest() {
char c;
- LocAsIntegerTest t(&c);
+ INIT(LocAsIntegerTest, (&c));
}
//===----------------------------------------------------------------------===//
@@ -60,7 +73,7 @@ class NullPtrTest {
};
void fNullPtrTest() {
- NullPtrTest();
+ INIT(NullPtrTest, ());
}
//===----------------------------------------------------------------------===//
@@ -140,7 +153,7 @@ class HeapPointerTest1 {
};
void fHeapPointerTest1() {
- HeapPointerTest1();
+ INIT(HeapPointerTest1, ());
}
class HeapPointerTest2 {
@@ -160,7 +173,7 @@ class HeapPointerTest2 {
};
void fHeapPointerTest2() {
- HeapPointerTest2();
+ INIT(HeapPointerTest2, ());
}
//===----------------------------------------------------------------------===//
@@ -187,7 +200,7 @@ class StackPointerTest1 {
void fStackPointerTest1() {
int ok_a = 28;
StackPointerTest1::RecordType ok_rec{29, 30};
- StackPointerTest1(&ok_a, &ok_rec); // 'a', 'rec.x', 'rec.y' uninitialized
+ INIT(StackPointerTest1, (&ok_a, &ok_rec)); // 'a', 'rec.x', 'rec.y' uninitialized
}
#ifdef PEDANTIC
@@ -210,7 +223,7 @@ class StackPointerTest2 {
void fStackPointerTest2() {
int a;
StackPointerTest2::RecordType rec;
- StackPointerTest2(&a, &rec); // 'a', 'rec.x', 'rec.y' uninitialized
+ INIT(StackPointerTest2, (&a, &rec)); // 'a', 'rec.x', 'rec.y' uninitialized
}
#else
class StackPointerTest2 {
@@ -232,7 +245,7 @@ class StackPointerTest2 {
void fStackPointerTest2() {
int a;
StackPointerTest2::RecordType rec;
- StackPointerTest2(&a, &rec); // 'a', 'rec.x', 'rec.y' uninitialized
+ INIT(StackPointerTest2, (&a, &rec)); // 'a', 'rec.x', 'rec.y' uninitialized
}
#endif // PEDANTIC
@@ -251,7 +264,7 @@ class UninitPointerTest {
};
void fUninitPointerTest() {
- UninitPointerTest();
+ INIT(UninitPointerTest, ());
}
struct CharPointerTest {
@@ -262,7 +275,7 @@ struct CharPointerTest {
};
void fCharPointerTest() {
- CharPointerTest();
+ INIT(CharPointerTest, ());
}
struct VectorSizePointer {
@@ -272,7 +285,7 @@ struct VectorSizePointer {
};
void __vector_size__PointerTest() {
- VectorSizePointer v;
+ INIT(VectorSizePointer, ());
}
struct VectorSizePointee {
@@ -285,7 +298,7 @@ struct VectorSizePointee {
void __vector_size__PointeeTest() {
VectorSizePointee::MyVectorType i;
// TODO: Report v.x's pointee.
- VectorSizePointee v(&i);
+ INIT(VectorSizePointee, (&i));
}
struct CyclicPointerTest1 {
@@ -296,7 +309,7 @@ struct CyclicPointerTest1 {
};
void fCyclicPointerTest1() {
- CyclicPointerTest1();
+ INIT(CyclicPointerTest1, ());
}
struct CyclicPointerTest2 {
@@ -307,7 +320,7 @@ struct CyclicPointerTest2 {
};
void fCyclicPointerTest2() {
- CyclicPointerTest2();
+ INIT(CyclicPointerTest2, ());
}
//===----------------------------------------------------------------------===//
@@ -332,7 +345,7 @@ class VoidPointerTest1 {
void fVoidPointerTest1() {
void *vptr = calloc(1, sizeof(int));
- VoidPointerTest1(vptr, char());
+ INIT(VoidPointerTest1, (vptr, char()));
free(vptr);
}
@@ -347,7 +360,7 @@ class VoidPointerTest2 {
void fVoidPointerTest2() {
void *vptr = calloc(1, sizeof(int));
- VoidPointerTest2(&vptr, char());
+ INIT(VoidPointerTest2, (&vptr, char()));
free(vptr);
}
@@ -413,7 +426,7 @@ struct CyclicVoidPointerTest {
};
void fCyclicVoidPointerTest() {
- CyclicVoidPointerTest();
+ INIT(CyclicVoidPointerTest, ());
}
struct IntDynTypedVoidPointerTest1 {
@@ -425,7 +438,7 @@ struct IntDynTypedVoidPointerTest1 {
void fIntDynTypedVoidPointerTest1() {
int a;
- IntDynTypedVoidPointerTest1 tmp(&a);
+ INIT(IntDynTypedVoidPointerTest1, (&a));
}
struct RecordDynTypedVoidPointerTest {
@@ -442,7 +455,7 @@ struct RecordDynTypedVoidPointerTest {
void fRecordDynTypedVoidPointerTest() {
RecordDynTypedVoidPointerTest::RecordType a;
- RecordDynTypedVoidPointerTest tmp(&a);
+ INIT(RecordDynTypedVoidPointerTest, (&a));
}
struct NestedNonVoidDynTypedVoidPointerTest {
@@ -463,7 +476,7 @@ struct NestedNonVoidDynTypedVoidPointerTest {
void fNestedNonVoidDynTypedVoidPointerTest() {
NestedNonVoidDynTypedVoidPointerTest::RecordType a;
char c;
- NestedNonVoidDynTypedVoidPointerTest tmp(&a, &c);
+ INIT(NestedNonVoidDynTypedVoidPointerTest, (&a, &c));
}
//===----------------------------------------------------------------------===//
@@ -489,7 +502,7 @@ class MultiPointerTest1 {
void fMultiPointerTest1() {
MultiPointerTest1::RecordType *p1;
MultiPointerTest1::RecordType **mptr = &p1;
- MultiPointerTest1(mptr, int()); // '*mptr' uninitialized
+ INIT(MultiPointerTest1, (mptr, int())); // '*mptr' uninitialized
}
#else
class MultiPointerTest1 {
@@ -509,7 +522,7 @@ class MultiPointerTest1 {
void fMultiPointerTest1() {
MultiPointerTest1::RecordType *p1;
MultiPointerTest1::RecordType **mptr = &p1;
- MultiPointerTest1(mptr, int()); // '*mptr' uninitialized
+ INIT(MultiPointerTest1, (mptr, int())); // '*mptr' uninitialized
}
#endif // PEDANTIC
@@ -533,7 +546,7 @@ void fMultiPointerTest2() {
MultiPointerTest2::RecordType i;
MultiPointerTest2::RecordType *p1 = &i;
MultiPointerTest2::RecordType **mptr = &p1;
- MultiPointerTest2(mptr, int()); // '**mptr' uninitialized
+ INIT(MultiPointerTest2, (mptr, int())); // '**mptr' uninitialized
}
#else
class MultiPointerTest2 {
@@ -555,7 +568,7 @@ void fMultiPointerTest2() {
MultiPointerTest2::RecordType i;
MultiPointerTest2::RecordType *p1 = &i;
MultiPointerTest2::RecordType **mptr = &p1;
- MultiPointerTest2(mptr, int()); // '**mptr' uninitialized
+ INIT(MultiPointerTest2, (mptr, int())); // '**mptr' uninitialized
}
#endif // PEDANTIC
@@ -579,7 +592,7 @@ void fMultiPointerTest3() {
MultiPointerTest3::RecordType i{31, 32};
MultiPointerTest3::RecordType *p1 = &i;
MultiPointerTest3::RecordType **mptr = &p1;
- MultiPointerTest3(mptr, int()); // '**mptr' uninitialized
+ INIT(MultiPointerTest3, (mptr, int())); // '**mptr' uninitialized
}
//===----------------------------------------------------------------------===//
@@ -596,7 +609,7 @@ struct IncompletePointeeTypeTest {
};
void fIncompletePointeeTypeTest(void *ptr) {
- IncompletePointeeTypeTest(reinterpret_cast<IncompleteType *>(ptr));
+ INIT(IncompletePointeeTypeTest, (reinterpret_cast<IncompleteType *>(ptr)));
}
//===----------------------------------------------------------------------===//
@@ -633,7 +646,7 @@ struct PointerToMemberFunctionTest1 {
};
void fPointerToMemberFunctionTest1() {
- PointerToMemberFunctionTest1(); // expected-warning{{1 uninitialized field}}
+ INIT(PointerToMemberFunctionTest1, ()); // expected-warning{{1 uninitialized field}}
}
struct PointerToMemberFunctionTest2 {
@@ -645,7 +658,7 @@ struct PointerToMemberFunctionTest2 {
void fPointerToMemberFunctionTest2() {
void (UsefulFunctions::*f)(void) = &UsefulFunctions::print;
- PointerToMemberFunctionTest2 a(f);
+ INIT(PointerToMemberFunctionTest2, (f));
}
struct MultiPointerToMemberFunctionTest1 {
@@ -654,7 +667,7 @@ struct MultiPointerToMemberFunctionTest1 {
};
void fMultiPointerToMemberFunctionTest1() {
- MultiPointerToMemberFunctionTest1(); // expected-warning{{1 uninitialized field}}
+ INIT(MultiPointerToMemberFunctionTest1, ()); // expected-warning{{1 uninitialized field}}
}
struct MultiPointerToMemberFunctionTest2 {
@@ -666,7 +679,7 @@ struct MultiPointerToMemberFunctionTest2 {
void fMultiPointerToMemberFunctionTest2() {
void (UsefulFunctions::*f)(void) = &UsefulFunctions::print;
- MultiPointerToMemberFunctionTest2 a(&f);
+ INIT(MultiPointerToMemberFunctionTest2, (&f));
}
struct PointerToMemberDataTest1 {
@@ -675,7 +688,7 @@ struct PointerToMemberDataTest1 {
};
void fPointerToMemberDataTest1() {
- PointerToMemberDataTest1(); // expected-warning{{1 uninitialized field}}
+ INIT(PointerToMemberDataTest1, ()); // expected-warning{{1 uninitialized field}}
}
struct PointerToMemberDataTest2 {
@@ -687,7 +700,7 @@ struct PointerToMemberDataTest2 {
void fPointerToMemberDataTest2() {
int UsefulFunctions::*d = &UsefulFunctions::a;
- PointerToMemberDataTest2 a(d);
+ INIT(PointerToMemberDataTest2, (d));
}
struct MultiPointerToMemberDataTest1 {
@@ -696,7 +709,7 @@ struct MultiPointerToMemberDataTest1 {
};
void fMultiPointerToMemberDataTest1() {
- MultiPointerToMemberDataTest1(); // expected-warning{{1 uninitialized field}}
+ INIT(MultiPointerToMemberDataTest1, ()); // expected-warning{{1 uninitialized field}}
}
struct MultiPointerToMemberDataTest2 {
@@ -708,7 +721,7 @@ struct MultiPointerToMemberDataTest2 {
void fMultiPointerToMemberDataTest2() {
int UsefulFunctions::*d = &UsefulFunctions::a;
- MultiPointerToMemberDataTest2 a(&d);
+ INIT(MultiPointerToMemberDataTest2, (&d));
}
#endif // PEDANTIC
@@ -733,7 +746,7 @@ class ListTest1 {
};
void fListTest1() {
- ListTest1();
+ INIT(ListTest1, ());
}
class ListTest2 {
@@ -753,7 +766,7 @@ class ListTest2 {
void fListTest2() {
ListTest2::Node n;
- ListTest2(&n, int());
+ INIT(ListTest2, (&n, int()));
}
class CyclicList {
@@ -787,7 +800,7 @@ void fCyclicList() {
n3.i = 50;
n1.next = &n3;
// note that n1.i is uninitialized
- CyclicList(&n1, int());
+ INIT(CyclicList, (&n1, int()));
}
struct RingListTest {
@@ -796,7 +809,7 @@ struct RingListTest {
};
void fRingListTest() {
- RingListTest();
+ INIT(RingListTest, ());
}
//===----------------------------------------------------------------------===//
@@ -822,7 +835,7 @@ class ReferenceTest1 {
void fReferenceTest1() {
ReferenceTest1::RecordType d{33, 34};
- ReferenceTest1(d, d);
+ INIT(ReferenceTest1, (d, d));
}
#ifdef PEDANTIC
@@ -845,7 +858,7 @@ class ReferenceTest2 {
void fReferenceTest2() {
ReferenceTest2::RecordType c;
- ReferenceTest2(c, c);
+ INIT(ReferenceTest2, (c, c));
}
#else
class ReferenceTest2 {
@@ -867,7 +880,7 @@ class ReferenceTest2 {
void fReferenceTest2() {
ReferenceTest2::RecordType c;
- ReferenceTest2(c, c);
+ INIT(ReferenceTest2, (c, c));
}
#endif // PEDANTIC
@@ -890,7 +903,7 @@ class ReferenceTest3 {
void fReferenceTest3() {
ReferenceTest3::RecordType c, d{35, 36};
- ReferenceTest3(c, d);
+ INIT(ReferenceTest3, (c, d));
}
class ReferenceTest4 {
@@ -912,7 +925,7 @@ class ReferenceTest4 {
void fReferenceTest5() {
ReferenceTest4::RecordType c, d{37, 38};
- ReferenceTest4(d, c);
+ INIT(ReferenceTest4, (d, c));
}
//===----------------------------------------------------------------------===//
@@ -930,7 +943,7 @@ struct IntMultipleReferenceToSameObjectTest {
void fIntMultipleReferenceToSameObjectTest() {
int a;
- IntMultipleReferenceToSameObjectTest Test(&a);
+ INIT(IntMultipleReferenceToSameObjectTest, (&a));
}
struct IntReferenceWrapper1 {
@@ -951,7 +964,6 @@ struct IntReferenceWrapper2 {
void fMultipleObjectsReferencingTheSameObjectTest() {
int a;
-
- IntReferenceWrapper1 T1(a);
- IntReferenceWrapper2 T2(a);
+ INIT(IntReferenceWrapper1, (a));
+ INIT(IntReferenceWrapper2, (a));
}
diff --git a/clang/test/Analysis/cxx-uninitialized-object-unguarded-access.cpp b/clang/test/Analysis/cxx-uninitialized-object-unguarded-access.cpp
index 611e1d8255976..cb41fbd1333e0 100644
--- a/clang/test/Analysis/cxx-uninitialized-object-unguarded-access.cpp
+++ b/clang/test/Analysis/cxx-uninitialized-object-unguarded-access.cpp
@@ -2,6 +2,16 @@
// RUN: -analyzer-config optin.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \
// RUN: -analyzer-config optin.cplusplus.UninitializedObject:IgnoreGuardedFields=true \
// RUN: -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.UninitializedObject \
+// RUN: -analyzer-config optin.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \
+// RUN: -analyzer-config optin.cplusplus.UninitializedObject:IgnoreGuardedFields=true \
+// RUN: -std=c++11 -verify %s -DHEAP_ALLOCATION
+
+#ifdef HEAP_ALLOCATION
+#define INIT(CLS, ARGS) new CLS ARGS
+#else
+#define INIT(CLS, ARGS) (void) CLS ARGS
+#endif
//===----------------------------------------------------------------------===//
// Helper functions for tests.
@@ -55,8 +65,8 @@ class NoUnguardedFieldsTest {
};
void fNoUnguardedFieldsTest() {
- NoUnguardedFieldsTest T1(NoUnguardedFieldsTest::Kind::A);
- NoUnguardedFieldsTest T2(NoUnguardedFieldsTest::Kind::V);
+ INIT(NoUnguardedFieldsTest, (NoUnguardedFieldsTest::Kind::A));
+ INIT(NoUnguardedFieldsTest, (NoUnguardedFieldsTest::Kind::V));
}
class NoUngardedFieldsNoReturnFuncCalledTest {
@@ -94,10 +104,8 @@ class NoUngardedFieldsNoReturnFuncCalledTest {
};
void fNoUngardedFieldsNoReturnFuncCalledTest() {
- NoUngardedFieldsNoReturnFuncCalledTest
- T1(NoUngardedFieldsNoReturnFuncCalledTest::Kind::A);
- NoUngardedFieldsNoReturnFuncCalledTest
- T2(NoUngardedFieldsNoReturnFuncCalledTest::Kind::V);
+ INIT(NoUngardedFieldsNoReturnFuncCalledTest, (NoUngardedFieldsNoReturnFuncCalledTest::Kind::A));
+ INIT(NoUngardedFieldsNoReturnFuncCalledTest, (NoUngardedFieldsNoReturnFuncCalledTest::Kind::V));
}
class NoUnguardedFieldsWithUndefMethodTest {
@@ -139,10 +147,8 @@ class NoUnguardedFieldsWithUndefMethodTest {
};
void fNoUnguardedFieldsWithUndefMethodTest() {
- NoUnguardedFieldsWithUndefMethodTest
- T1(NoUnguardedFieldsWithUndefMethodTest::Kind::A);
- NoUnguardedFieldsWithUndefMethodTest
- T2(NoUnguardedFieldsWithUndefMethodTest::Kind::V);
+ INIT(NoUnguardedFieldsWithUndefMethodTest, (NoUnguardedFieldsWithUndefMethodTest::Kind::A));
+ INIT(NoUnguardedFieldsWithUndefMethodTest, (NoUnguardedFieldsWithUndefMethodTest::Kind::V));
}
class UnguardedFieldThroughMethodTest {
@@ -179,7 +185,7 @@ class UnguardedFieldThroughMethodTest {
};
void fUnguardedFieldThroughMethodTest() {
- UnguardedFieldThroughMethodTest T1(UnguardedFieldThroughMethodTest::Kind::A);
+ INIT(UnguardedFieldThroughMethodTest, (UnguardedFieldThroughMethodTest::Kind::A));
}
class UnguardedPublicFieldsTest {
@@ -218,7 +224,7 @@ class UnguardedPublicFieldsTest {
};
void fUnguardedPublicFieldsTest() {
- UnguardedPublicFieldsTest T1(UnguardedPublicFieldsTest::Kind::A);
+ INIT(UnguardedPublicFieldsTest, (UnguardedPublicFieldsTest::Kind::A));
}
//===----------------------------------------------------------------------===//
@@ -262,7 +268,7 @@ class UnguardedFalseNegativeTest1 {
};
void fUnguardedFalseNegativeTest1() {
- UnguardedFalseNegativeTest1 T1(UnguardedFalseNegativeTest1::Kind::A);
+ INIT(UnguardedFalseNegativeTest1, (UnguardedFalseNegativeTest1::Kind::A));
}
class UnguardedFalseNegativeTest2 {
@@ -300,7 +306,7 @@ class UnguardedFalseNegativeTest2 {
};
void fUnguardedFalseNegativeTest2() {
- UnguardedFalseNegativeTest2 T1(UnguardedFalseNegativeTest2::Kind::A);
+ INIT(UnguardedFalseNegativeTest2, (UnguardedFalseNegativeTest2::Kind::A));
}
//===----------------------------------------------------------------------===//
@@ -349,8 +355,8 @@ class IfGuardedFieldsTest {
};
void fIfGuardedFieldsTest() {
- IfGuardedFieldsTest T1(IfGuardedFieldsTest::Kind::A);
- IfGuardedFieldsTest T2(IfGuardedFieldsTest::Kind::V);
+ INIT(IfGuardedFieldsTest, (IfGuardedFieldsTest::Kind::A));
+ INIT(IfGuardedFieldsTest, (IfGuardedFieldsTest::Kind::V));
}
class SwitchGuardedFieldsTest {
@@ -396,8 +402,8 @@ class SwitchGuardedFieldsTest {
};
void fSwitchGuardedFieldsTest() {
- SwitchGuardedFieldsTest T1(SwitchGuardedFieldsTest::Kind::A);
- SwitchGuardedFieldsTest T2(SwitchGuardedFieldsTest::Kind::V);
+ INIT(SwitchGuardedFieldsTest, (SwitchGuardedFieldsTest::Kind::A));
+ INIT(SwitchGuardedFieldsTest, (SwitchGuardedFieldsTest::Kind::V));
}
class ConditionalOperatorGuardedFieldsTest {
@@ -433,8 +439,6 @@ class ConditionalOperatorGuardedFieldsTest {
};
void fConditionalOperatorGuardedFieldsTest() {
- ConditionalOperatorGuardedFieldsTest
- T1(ConditionalOperatorGuardedFieldsTest::Kind::A);
- ConditionalOperatorGuardedFieldsTest
- T2(ConditionalOperatorGuardedFieldsTest::Kind::V);
+ INIT(ConditionalOperatorGuardedFieldsTest, (ConditionalOperatorGuardedFieldsTest::Kind::A));
+ INIT(ConditionalOperatorGuardedFieldsTest, (ConditionalOperatorGuardedFieldsTest::Kind::V));
}
diff --git a/clang/test/Analysis/cxx-uninitialized-object-unionlike-constructs.cpp b/clang/test/Analysis/cxx-uninitialized-object-unionlike-constructs.cpp
index 92412f7cccb9d..ab5c23f282787 100644
--- a/clang/test/Analysis/cxx-uninitialized-object-unionlike-constructs.cpp
+++ b/clang/test/Analysis/cxx-uninitialized-object-unionlike-constructs.cpp
@@ -2,6 +2,10 @@
// RUN: -analyzer-config optin.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \
// RUN: -analyzer-config optin.cplusplus.UninitializedObject:IgnoreRecordsWithField="[Tt]ag|[Kk]ind" \
// RUN: -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.UninitializedObject \
+// RUN: -analyzer-config optin.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \
+// RUN: -analyzer-config optin.cplusplus.UninitializedObject:IgnoreRecordsWithField="[Tt]ag|[Kk]ind" \
+// RUN: -std=c++11 -verify %s -DHEAP_ALLOCATION
// RUN: not %clang_analyze_cc1 -verify %s \
// RUN: -analyzer-checker=core \
@@ -16,6 +20,11 @@
// CHECK-UNINIT-INVALID-REGEX-SAME: with error message "parentheses not
// CHECK-UNINIT-INVALID-REGEX-SAME: balanced"
+#ifdef HEAP_ALLOCATION
+#define INIT(CLS, ARGS) new CLS ARGS
+#else
+#define INIT(CLS, ARGS) (void) CLS ARGS
+#endif
// expected-no-diagnostics
@@ -42,7 +51,7 @@ struct UnionLikeStruct1 {
};
void fUnionLikeStruct1() {
- UnionLikeStruct1 t(UnionLikeStruct1::volume, 10);
+ INIT(UnionLikeStruct1, (UnionLikeStruct1::volume, 10));
}
// Only name contains "kind".
@@ -68,7 +77,7 @@ struct UnionLikeStruct2 {
};
void fUnionLikeStruct2() {
- UnionLikeStruct2 t(UnionLikeStruct2::volume, 10);
+ INIT(UnionLikeStruct2, (UnionLikeStruct2::volume, 10));
}
// Only type contains "kind".
@@ -94,7 +103,7 @@ struct UnionLikeStruct3 {
};
void fUnionLikeStruct3() {
- UnionLikeStruct3 t(UnionLikeStruct3::volume, 10);
+ INIT(UnionLikeStruct3, (UnionLikeStruct3::volume, 10));
}
// Only type contains "tag".
@@ -120,7 +129,7 @@ struct UnionLikeStruct4 {
};
void fUnionLikeStruct4() {
- UnionLikeStruct4 t(UnionLikeStruct4::volume, 10);
+ INIT(UnionLikeStruct4, (UnionLikeStruct4::volume, 10));
}
// Both name and type name contains but does not equal to tag/kind.
@@ -146,5 +155,5 @@ struct UnionLikeStruct5 {
};
void fUnionLikeStruct5() {
- UnionLikeStruct5 t(UnionLikeStruct5::volume, 10);
+ INIT(UnionLikeStruct5, (UnionLikeStruct5::volume, 10));
}
diff --git a/clang/test/Analysis/cxx-uninitialized-object.cpp b/clang/test/Analysis/cxx-uninitialized-object.cpp
index daaf6f418c7d1..adaf2470f453e 100644
--- a/clang/test/Analysis/cxx-uninitialized-object.cpp
+++ b/clang/test/Analysis/cxx-uninitialized-object.cpp
@@ -4,12 +4,29 @@
// RUN: -analyzer-config optin.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \
// RUN: -analyzer-config \
// RUN: optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true
+// RUN: %clang_analyze_cc1 -std=c++14 -verify %s \
+// RUN: -analyzer-checker=core \
+// RUN: -analyzer-checker=optin.cplusplus.UninitializedObject \
+// RUN: -analyzer-config optin.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \
+// RUN: -analyzer-config \
+// RUN: optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true -DHEAP_ALLOCATION
// RUN: %clang_analyze_cc1 -std=c++14 -verify %s \
// RUN: -analyzer-checker=core \
// RUN: -analyzer-checker=optin.cplusplus.UninitializedObject \
// RUN: -analyzer-config \
// RUN: optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true
+// RUN: %clang_analyze_cc1 -std=c++14 -verify %s \
+// RUN: -analyzer-checker=core \
+// RUN: -analyzer-checker=optin.cplusplus.UninitializedObject \
+// RUN: -analyzer-config \
+// RUN: optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true -DHEAP_ALLOCATION
+
+#ifdef HEAP_ALLOCATION
+#define INIT(CLS, ARGS) new CLS ARGS
+#else
+#define INIT(CLS, ARGS) (void) CLS ARGS
+#endif
//===----------------------------------------------------------------------===//
// Default constructor test.
@@ -23,7 +40,7 @@ class CompilerGeneratedConstructorTest {
};
void fCompilerGeneratedConstructorTest() {
- CompilerGeneratedConstructorTest();
+ INIT(CompilerGeneratedConstructorTest, ());
}
#ifdef PEDANTIC
@@ -37,7 +54,7 @@ class DefaultConstructorTest {
DefaultConstructorTest::DefaultConstructorTest() = default;
void fDefaultConstructorTest() {
- DefaultConstructorTest(); // expected-warning{{1 uninitialized field}}
+ INIT(DefaultConstructorTest, ()); // expected-warning{{1 uninitialized field}}
}
#else
class DefaultConstructorTest {
@@ -50,7 +67,7 @@ class DefaultConstructorTest {
DefaultConstructorTest::DefaultConstructorTest() = default;
void fDefaultConstructorTest() {
- DefaultConstructorTest();
+ INIT(DefaultConstructorTest, ());
}
#endif // PEDANTIC
@@ -71,7 +88,7 @@ class InitListTest1 {
};
void fInitListTest1() {
- InitListTest1();
+ INIT(InitListTest1, ());
}
class InitListTest2 {
@@ -84,7 +101,7 @@ class InitListTest2 {
};
void fInitListTest2() {
- InitListTest2();
+ INIT(InitListTest2, ());
}
class InitListTest3 {
@@ -97,7 +114,7 @@ class InitListTest3 {
};
void fInitListTest3() {
- InitListTest3();
+ INIT(InitListTest3, ());
}
//===----------------------------------------------------------------------===//
@@ -116,7 +133,7 @@ class CtorBodyTest1 {
};
void fCtorBodyTest1() {
- CtorBodyTest1();
+ INIT(CtorBodyTest1, ());
}
class CtorBodyTest2 {
@@ -130,7 +147,7 @@ class CtorBodyTest2 {
};
void fCtorBodyTest2() {
- CtorBodyTest2();
+ INIT(CtorBodyTest2, ());
}
class CtorBodyTest3 {
@@ -144,7 +161,7 @@ class CtorBodyTest3 {
};
void fCtorBodyTest3() {
- CtorBodyTest3();
+ INIT(CtorBodyTest3, ());
}
#ifdef PEDANTIC
@@ -157,7 +174,7 @@ class CtorBodyTest4 {
};
void fCtorBodyTest4() {
- CtorBodyTest4(); // expected-warning{{2 uninitialized fields}}
+ INIT(CtorBodyTest4, ()); // expected-warning{{2 uninitialized fields}}
}
#else
class CtorBodyTest4 {
@@ -169,7 +186,7 @@ class CtorBodyTest4 {
};
void fCtorBodyTest4() {
- CtorBodyTest4();
+ INIT(CtorBodyTest4, ());
}
#endif
@@ -195,7 +212,7 @@ class CtorDelegationTest1 {
};
void fCtorDelegationTest1() {
- CtorDelegationTest1();
+ INIT(CtorDelegationTest1, ());
}
class CtorDelegationTest2 {
@@ -214,7 +231,7 @@ class CtorDelegationTest2 {
};
void fCtorDelegationTest2() {
- CtorDelegationTest2();
+ INIT(CtorDelegationTest2, ());
}
//===----------------------------------------------------------------------===//
@@ -238,7 +255,7 @@ class ContainsRecordTest1 {
};
void fContainsRecordTest1() {
- ContainsRecordTest1();
+ INIT(ContainsRecordTest1, ());
}
class ContainsRecordTest2 {
@@ -257,7 +274,7 @@ class ContainsRecordTest2 {
};
void fContainsRecordTest2() {
- ContainsRecordTest2();
+ INIT(ContainsRecordTest2, ());
}
class ContainsRecordTest3 {
@@ -275,7 +292,7 @@ class ContainsRecordTest3 {
};
void fContainsRecordTest3() {
- ContainsRecordTest3();
+ INIT(ContainsRecordTest3, ());
}
class ContainsRecordTest4 {
@@ -292,7 +309,7 @@ class ContainsRecordTest4 {
};
void fContainsRecordTest4() {
- ContainsRecordTest4();
+ INIT(ContainsRecordTest4, ());
}
//===----------------------------------------------------------------------===//
@@ -313,7 +330,7 @@ class IntTemplateClassTest1 {
};
void fIntTemplateClassTest1() {
- IntTemplateClassTest1<int>(22);
+ INIT(IntTemplateClassTest1<int>, (22));
}
template <class T>
@@ -328,7 +345,7 @@ class IntTemplateClassTest2 {
};
void fIntTemplateClassTest2() {
- IntTemplateClassTest2<int>();
+ INIT(IntTemplateClassTest2<int>, ());
}
struct Record {
@@ -348,7 +365,7 @@ class RecordTemplateClassTest {
};
void fRecordTemplateClassTest() {
- RecordTemplateClassTest<Record>();
+ INIT(RecordTemplateClassTest<Record>, ());
}
//===----------------------------------------------------------------------===//
@@ -383,9 +400,9 @@ class PassingToUnknownFunctionTest1 {
};
void fPassingToUnknownFunctionTest1() {
- PassingToUnknownFunctionTest1();
- PassingToUnknownFunctionTest1(int());
- PassingToUnknownFunctionTest1(int(), int());
+ INIT(PassingToUnknownFunctionTest1, ());
+ INIT(PassingToUnknownFunctionTest1, (int()));
+ INIT(PassingToUnknownFunctionTest1, (int(), int()));
}
class PassingToUnknownFunctionTest2 {
@@ -400,7 +417,7 @@ class PassingToUnknownFunctionTest2 {
};
void fPassingToUnknownFunctionTest2() {
- PassingToUnknownFunctionTest2();
+ INIT(PassingToUnknownFunctionTest2, ());
}
//===----------------------------------------------------------------------===//
@@ -427,7 +444,7 @@ class ContainsSimpleUnionTest1 {
};
void fContainsSimpleUnionTest1() {
- ContainsSimpleUnionTest1();
+ INIT(ContainsSimpleUnionTest1, ());
}
class ContainsSimpleUnionTest2 {
@@ -444,7 +461,7 @@ class ContainsSimpleUnionTest2 {
void fContainsSimpleUnionTest2() {
// TODO: we'd expect the warning: {{1 uninitialized field}}
- ContainsSimpleUnionTest2(); // no-warning
+ INIT(ContainsSimpleUnionTest2, ()); // no-warning
}
class UnionPointerTest1 {
@@ -467,7 +484,7 @@ class UnionPointerTest1 {
void fUnionPointerTest1() {
UnionPointerTest1::SimpleUnion u;
u.uf = 41;
- UnionPointerTest1(&u, int());
+ INIT(UnionPointerTest1, (&u, int()));
}
class UnionPointerTest2 {
@@ -489,7 +506,7 @@ class UnionPointerTest2 {
void fUnionPointerTest2() {
UnionPointerTest2::SimpleUnion u;
// TODO: we'd expect the warning: {{1 uninitialized field}}
- UnionPointerTest2(&u, int()); // no-warning
+ INIT(UnionPointerTest2, (&u, int())); // no-warning
}
class ContainsUnionWithRecordTest1 {
@@ -512,7 +529,7 @@ class ContainsUnionWithRecordTest1 {
};
void fContainsUnionWithRecordTest1() {
- ContainsUnionWithRecordTest1();
+ INIT(ContainsUnionWithRecordTest1, ());
}
class ContainsUnionWithRecordTest2 {
@@ -535,7 +552,7 @@ class ContainsUnionWithRecordTest2 {
};
void fContainsUnionWithRecordTest2() {
- ContainsUnionWithRecordTest1();
+ INIT(ContainsUnionWithRecordTest1, ());
}
class ContainsUnionWithRecordTest3 {
@@ -561,7 +578,7 @@ class ContainsUnionWithRecordTest3 {
};
void fContainsUnionWithRecordTest3() {
- ContainsUnionWithRecordTest3();
+ INIT(ContainsUnionWithRecordTest3, ());
}
class ContainsUnionWithSimpleUnionTest1 {
@@ -583,7 +600,7 @@ class ContainsUnionWithSimpleUnionTest1 {
};
void fContainsUnionWithSimpleUnionTest1() {
- ContainsUnionWithSimpleUnionTest1();
+ INIT(ContainsUnionWithSimpleUnionTest1, ());
}
class ContainsUnionWithSimpleUnionTest2 {
@@ -604,7 +621,7 @@ class ContainsUnionWithSimpleUnionTest2 {
void fContainsUnionWithSimpleUnionTest2() {
// TODO: we'd expect the warning: {{1 uninitialized field}}
- ContainsUnionWithSimpleUnionTest2(); // no-warning
+ INIT(ContainsUnionWithSimpleUnionTest2, ()); // no-warning
}
//===----------------------------------------------------------------------===//
@@ -636,8 +653,7 @@ struct CopyConstructorTest {
void fCopyConstructorTest() {
CopyConstructorTest cct;
- CopyConstructorTest copy = cct; // expected-warning{{1 uninitialized field}}
- funcToSquelchCompilerWarnings(copy);
+ INIT(CopyConstructorTest, (cct)); // expected-warning{{1 uninitialized field}}
}
#else
struct CopyConstructorTest {
@@ -649,8 +665,7 @@ struct CopyConstructorTest {
void fCopyConstructorTest() {
CopyConstructorTest cct;
- CopyConstructorTest copy = cct;
- funcToSquelchCompilerWarnings(copy);
+ INIT(CopyConstructorTest, (cct));
}
#endif // PEDANTIC
@@ -666,8 +681,7 @@ struct MoveConstructorTest {
void fMoveConstructorTest() {
MoveConstructorTest cct;
// TODO: we'd expect the warning: {{1 uninitialized field}}
- MoveConstructorTest copy(static_cast<MoveConstructorTest &&>(cct)); // no-warning
- funcToSquelchCompilerWarnings(copy);
+ INIT(MoveConstructorTest, (static_cast<MoveConstructorTest &&>(cct))); // no-warning
}
//===----------------------------------------------------------------------===//
@@ -683,7 +697,7 @@ struct IntArrayTest {
};
void fIntArrayTest() {
- IntArrayTest();
+ INIT(IntArrayTest, ());
}
struct RecordTypeArrayTest {
@@ -697,7 +711,7 @@ struct RecordTypeArrayTest {
};
void fRecordTypeArrayTest() {
- RecordTypeArrayTest();
+ INIT(RecordTypeArrayTest, ());
}
template <class T>
@@ -726,7 +740,7 @@ struct MemsetTest1 {
};
void fMemsetTest1() {
- MemsetTest1();
+ INIT(MemsetTest1, ());
}
struct MemsetTest2 {
@@ -738,7 +752,7 @@ struct MemsetTest2 {
};
void fMemsetTest2() {
- MemsetTest2();
+ INIT(MemsetTest2, ());
}
//===----------------------------------------------------------------------===//
@@ -772,7 +786,7 @@ struct LambdaTest1 {
void fLambdaTest1() {
auto isEven = [](int a) { return a % 2 == 0; };
- LambdaTest1<decltype(isEven)>(isEven, int());
+ INIT(LambdaTest1<decltype(isEven)>, (isEven, int()));
}
#ifdef PEDANTIC
@@ -786,7 +800,7 @@ struct LambdaTest2 {
void fLambdaTest2() {
int b;
auto equals = [&b](int a) { return a == b; }; // expected-note{{uninitialized pointee 'this->functor./*captured variable*/b'}}
- LambdaTest2<decltype(equals)>(equals, int());
+ INIT(LambdaTest2<decltype(equals)>, (equals, int()));
}
#else
template <class Callable>
@@ -799,7 +813,7 @@ struct LambdaTest2 {
void fLambdaTest2() {
int b;
auto equals = [&b](int a) { return a == b; };
- LambdaTest2<decltype(equals)>(equals, int());
+ INIT(LambdaTest2<decltype(equals)>, (equals, int()));
}
#endif //PEDANTIC
@@ -824,7 +838,7 @@ void fLambdaTest3() {
auto equals = [&rec1](LT3Detail::RecordType rec2) {
return rec1.x == rec2.x;
};
- LambdaTest3<decltype(equals)>(equals, int());
+ INIT(LambdaTest3<decltype(equals)>, (equals, int()));
}
#else
namespace LT3Detail {
@@ -847,7 +861,7 @@ void fLambdaTest3() {
auto equals = [&rec1](LT3Detail::RecordType rec2) {
return rec1.x == rec2.x;
};
- LambdaTest3<decltype(equals)>(equals, int());
+ INIT(LambdaTest3<decltype(equals)>, (equals, int()));
}
#endif //PEDANTIC
@@ -863,7 +877,7 @@ void fMultipleLambdaCapturesTest1() {
int b1, b2 = 3, b3;
auto equals = [&b1, &b2, &b3](int a) { return a == b1 == b2 == b3; }; // expected-note{{uninitialized pointee 'this->functor./*captured variable*/b1'}}
// expected-note at -1{{uninitialized pointee 'this->functor./*captured variable*/b3'}}
- MultipleLambdaCapturesTest1<decltype(equals)>(equals, int());
+ INIT(MultipleLambdaCapturesTest1<decltype(equals)>, (equals, int()));
}
template <class Callable>
@@ -877,7 +891,7 @@ struct MultipleLambdaCapturesTest2 {
void fMultipleLambdaCapturesTest2() {
int b1, b2 = 3, b3;
auto equals = [b1, &b2, &b3](int a) { return a == b1 == b2 == b3; }; // expected-note{{uninitialized pointee 'this->functor./*captured variable*/b3'}}
- MultipleLambdaCapturesTest2<decltype(equals)>(equals, int());
+ INIT(MultipleLambdaCapturesTest2<decltype(equals)>, (equals, int()));
}
struct LambdaWrapper {
@@ -920,7 +934,7 @@ struct SystemHeaderTest1 {
};
void fSystemHeaderTest1() {
- SystemHeaderTest1();
+ INIT(SystemHeaderTest1, ());
}
#ifdef PEDANTIC
@@ -936,7 +950,7 @@ struct SystemHeaderTest2 {
void fSystemHeaderTest2() {
SystemHeaderTest2::RecordType rec;
- SystemHeaderTest2(rec, int());
+ INIT(SystemHeaderTest2, (rec, int()));
}
#else
struct SystemHeaderTest2 {
@@ -951,7 +965,7 @@ struct SystemHeaderTest2 {
void fSystemHeaderTest2() {
SystemHeaderTest2::RecordType rec;
- SystemHeaderTest2(rec, int());
+ INIT(SystemHeaderTest2, (rec, int()));
}
#endif //PEDANTIC
@@ -969,7 +983,7 @@ struct IncompleteTypeTest1 {
};
void fIncompleteTypeTest1() {
- IncompleteTypeTest1();
+ INIT(IncompleteTypeTest1, ());
}
struct IncompleteTypeTest2 {
@@ -983,7 +997,7 @@ struct IncompleteTypeTest2 {
};
void fIncompleteTypeTest2() {
- IncompleteTypeTest2();
+ INIT(IncompleteTypeTest2, ());
}
struct IncompleteTypeTest3 {
@@ -997,7 +1011,7 @@ struct IncompleteTypeTest3 {
};
void fIncompleteTypeTest3() {
- IncompleteTypeTest3();
+ INIT(IncompleteTypeTest3, ());
}
//===----------------------------------------------------------------------===//
@@ -1012,7 +1026,7 @@ struct IntegralTypeTest {
};
void fIntegralTypeTest() {
- IntegralTypeTest();
+ INIT(IntegralTypeTest, ());
}
struct FloatingTypeTest {
@@ -1023,7 +1037,7 @@ struct FloatingTypeTest {
};
void fFloatingTypeTest() {
- FloatingTypeTest();
+ INIT(FloatingTypeTest, ());
}
struct NullptrTypeTypeTest {
@@ -1034,7 +1048,7 @@ struct NullptrTypeTypeTest {
};
void fNullptrTypeTypeTest() {
- NullptrTypeTypeTest();
+ INIT(NullptrTypeTypeTest, ());
}
struct EnumTest {
@@ -1052,7 +1066,7 @@ struct EnumTest {
};
void fEnumTest() {
- EnumTest();
+ INIT(EnumTest, ());
}
//===----------------------------------------------------------------------===//
@@ -1090,7 +1104,7 @@ struct SingletonTest {
int dontGetFilteredByNonPedanticMode = 0;
SingletonTest() {
- Singleton();
+ INIT(Singleton, ());
}
};
@@ -1111,7 +1125,7 @@ struct CXX11MemberInitTest1 {
};
void fCXX11MemberInitTest1() {
- CXX11MemberInitTest1();
+ INIT(CXX11MemberInitTest1, ());
}
struct CXX11MemberInitTest2 {
@@ -1132,7 +1146,7 @@ struct CXX11MemberInitTest2 {
void fCXX11MemberInitTest2() {
// TODO: we'd expect the warning: {{2 uninitializeds field}}
- CXX11MemberInitTest2(); // no-warning
+ INIT(CXX11MemberInitTest2, ()); // no-warning
}
//===----------------------------------------------------------------------===//
@@ -1147,7 +1161,7 @@ struct MyAtomicInt {
};
void _AtomicTest() {
- MyAtomicInt b;
+ INIT(MyAtomicInt, ());
}
struct VectorSizeLong {
@@ -1158,6 +1172,7 @@ struct VectorSizeLong {
void __vector_size__LongTest() {
// TODO: Warn for v.x.
VectorSizeLong v;
+ new VectorSizeLong();
v.x[0] = 0;
}
@@ -1177,10 +1192,10 @@ struct ComplexInitTest {
};
void fComplexTest() {
- ComplexInitTest x;
+ INIT(ComplexInitTest, ());
// TODO: we should emit a warning for x2.x and x2.y.
- ComplexUninitTest x2;
+ INIT(ComplexUninitTest, ());
}
struct PaddingBitfieldTest {
diff --git a/clang/test/Analysis/objcpp-uninitialized-object.mm b/clang/test/Analysis/objcpp-uninitialized-object.mm
index f5a4d7ae8564b..15d9bb9b5c628 100644
--- a/clang/test/Analysis/objcpp-uninitialized-object.mm
+++ b/clang/test/Analysis/objcpp-uninitialized-object.mm
@@ -1,4 +1,11 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.UninitializedObject -std=c++11 -fblocks -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.UninitializedObject -std=c++11 -fblocks -verify %s -DHEAP_ALLOCATION
+
+#ifdef HEAP_ALLOCATION
+#define INIT(CLS, ARGS) new CLS ARGS
+#else
+#define INIT(CLS, ARGS) (void) CLS ARGS
+#endif
typedef void (^myBlock) ();
@@ -14,11 +21,11 @@
};
void warnOnUninitializedBlock() {
- StructWithBlock a(10);
+ INIT(StructWithBlock, (10));
}
void noWarningWhenInitialized() {
- StructWithBlock a;
+ INIT(StructWithBlock, ());
}
struct StructWithId {
@@ -28,5 +35,5 @@ void noWarningWhenInitialized() {
};
void warnOnUninitializedId() {
- StructWithId s;
+ INIT(StructWithId, ());
}
More information about the cfe-commits
mailing list