diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index d500ab3210584b..04ba89aa457e68 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -110,6 +110,7 @@ def FloatConversion : FloatZeroConversion]>; def FrameAddress : DiagGroup<"frame-address">; +def FreeNonHeapObject : DiagGroup<"free-nonheap-object">; def DoublePromotion : DiagGroup<"double-promotion">; def EnumTooLarge : DiagGroup<"enum-too-large">; def UnsupportedNan : DiagGroup<"unsupported-nan">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 7d36397a799305..e93657898f5827 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -7609,7 +7609,7 @@ def err_no_typeid_with_fno_rtti : Error< def err_no_dynamic_cast_with_fno_rtti : Error< "use of dynamic_cast requires -frtti">; def warn_no_dynamic_cast_with_rtti_disabled: Warning< - "dynamic_cast will not work since RTTI data is disabled by " + "dynamic_cast will not work since RTTI data is disabled by " "%select{-fno-rtti-data|/GR-}0">, InGroup; def warn_no_typeid_with_rtti_disabled: Warning< "typeid will not work since RTTI data is disabled by " @@ -7625,8 +7625,7 @@ def warn_condition_is_assignment : Warning<"using the result of an " InGroup; def warn_free_nonheap_object : Warning<"attempt to call %0 on non-heap object %1">, - InGroup>, - DefaultIgnore; // FIXME: add to -Wall after sufficient testing + InGroup; // Completely identical except off by default. def warn_condition_is_idiomatic_assignment : Warning<"using the result " diff --git a/clang/test/Analysis/NewDelete-intersections.mm b/clang/test/Analysis/NewDelete-intersections.mm index f01d62f8d365a3..6f81034ee349fd 100644 --- a/clang/test/Analysis/NewDelete-intersections.mm +++ b/clang/test/Analysis/NewDelete-intersections.mm @@ -24,9 +24,6 @@ extern "C" void free(void *); void testMallocFreeNoWarn() { - int i; - free(&i); // no warn - int *p1 = (int *)malloc(sizeof(int)); free(++p1); // no warn @@ -51,7 +48,7 @@ void testDeleteMalloced() { int *p2 = (int *)__builtin_alloca(sizeof(int)); delete p2; // no warn -} +} void testUseZeroAllocatedMalloced() { int *p1 = (int *)malloc(0); @@ -79,13 +76,13 @@ void testObjcFreeNewed() { } void testFreeAfterDelete() { - int *p = new int; + int *p = new int; delete p; free(p); // newdelete-warning{{Use of memory after it is freed}} } void testStandardPlacementNewAfterDelete() { - int *p = new int; + int *p = new int; delete p; p = new (p) int; // newdelete-warning{{Use of memory after it is freed}} } diff --git a/clang/test/Analysis/free.c b/clang/test/Analysis/free.c index 0d29bacf274cd1..b501457139244c 100644 --- a/clang/test/Analysis/free.c +++ b/clang/test/Analysis/free.c @@ -12,17 +12,23 @@ void *alloca(size_t); void t1 () { int a[] = { 1 }; - free(a); // expected-warning {{Argument to free() is the address of the local variable 'a', which is not memory allocated by malloc()}} + free(a); + // expected-warning@-1{{Argument to free() is the address of the local variable 'a', which is not memory allocated by malloc()}} + // expected-warning@-2{{attempt to call free on non-heap object 'a'}} } void t2 () { int a = 1; - free(&a); // expected-warning {{Argument to free() is the address of the local variable 'a', which is not memory allocated by malloc()}} + free(&a); + // expected-warning@-1{{Argument to free() is the address of the local variable 'a', which is not memory allocated by malloc()}} + // expected-warning@-2{{attempt to call free on non-heap object 'a'}} } void t3 () { static int a[] = { 1 }; - free(a); // expected-warning {{Argument to free() is the address of the static variable 'a', which is not memory allocated by malloc()}} + free(a); + // expected-warning@-1{{Argument to free() is the address of the static variable 'a', which is not memory allocated by malloc()}} + // expected-warning@-2{{attempt to call free on non-heap object 'a'}} } void t4 (char *x) { @@ -71,12 +77,16 @@ void t13 () { } void t14 (char a) { - free(&a); // expected-warning {{Argument to free() is the address of the parameter 'a', which is not memory allocated by malloc()}} + free(&a); + // expected-warning@-1{{Argument to free() is the address of the parameter 'a', which is not memory allocated by malloc()}} + // expected-warning@-2{{attempt to call free on non-heap object 'a'}} } static int someGlobal[2]; void t15 () { - free(someGlobal); // expected-warning {{Argument to free() is the address of the global variable 'someGlobal', which is not memory allocated by malloc()}} + free(someGlobal); + // expected-warning@-1{{Argument to free() is the address of the global variable 'someGlobal', which is not memory allocated by malloc()}} + // expected-warning@-2{{attempt to call free on non-heap object 'someGlobal'}} } void t16 (char **x, int offset) {