Index: clang/include/clang/Basic/DiagnosticGroups.td =================================================================== --- clang/include/clang/Basic/DiagnosticGroups.td +++ clang/include/clang/Basic/DiagnosticGroups.td @@ -110,6 +110,7 @@ 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">; Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -7604,7 +7604,7 @@ 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 " @@ -7620,8 +7620,7 @@ 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 " Index: clang/test/Analysis/NewDelete-intersections.mm =================================================================== --- clang/test/Analysis/NewDelete-intersections.mm +++ 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 @@ int *p2 = (int *)__builtin_alloca(sizeof(int)); delete p2; // no warn -} +} void testUseZeroAllocatedMalloced() { int *p1 = (int *)malloc(0); @@ -79,13 +76,13 @@ } 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}} } Index: clang/test/Analysis/free.c =================================================================== --- clang/test/Analysis/free.c +++ clang/test/Analysis/free.c @@ -12,17 +12,23 @@ 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 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) {