When operator new is used on a class with no constructor it generates an AGGR_INIT_EXPR, not a CALL_EXPR... with testcase. NPODB, static-checking only.
authorBenjamin Smedberg <benjamin@smedbergs.us>
Wed, 03 Dec 2008 11:49:54 -0500
changeset 22257 8d70108278252a5a0fb1161b262dd4c8c8beb8fc
parent 22256 2f18029ee8adde7e9035cbf433933c22acd4201d
child 22259 e8a66b1000919241ce19ad0c6599c80a9521f67d
push idunknown
push userunknown
push dateunknown
milestone1.9.2a1pre
When operator new is used on a class with no constructor it generates an AGGR_INIT_EXPR, not a CALL_EXPR... with testcase. NPODB, static-checking only.
xpcom/analysis/stack.js
xpcom/tests/static-checker/Makefile.in
xpcom/tests/static-checker/StackAggrInit.cpp
--- a/xpcom/analysis/stack.js
+++ b/xpcom/analysis/stack.js
@@ -162,21 +162,22 @@ function process_cp_pre_genericize(fndec
             
           case INIT_EXPR:
           case MODIFY_EXPR:
           case TARGET_EXPR:
             assign = assign.operands()[1];
             break;
 
           case CALL_EXPR:
+          case AGGR_INIT_EXPR:
             assign = stack[i + 1];
             break;
             
           default:
-            error("Unrecognized assignment from operator new: " + TREE_CODE(assign), getLocation());
+            error("Unrecognized assignment from operator new: %s. Tree code stack: %s".format(TREE_CODE(assign), [TREE_CODE(s) for each (s in stack)].join(",")), getLocation());
             return;
           }
           
           let destType = dehydra_convert(TREE_TYPE(assign));
           if (!destType.isPointer && !destType.isReference) {
             error("operator new not assigned to pointer/ref?", getLocation());
             return;
           }
--- a/xpcom/tests/static-checker/Makefile.in
+++ b/xpcom/tests/static-checker/Makefile.in
@@ -52,16 +52,17 @@ FINAL_FAILURE_TESTCASES = \
   $(NULL)
 
 STACK_FAILURE_TESTCASES = \
   TestStack.cpp \
   TestStackTemplate.cpp \
   StackNoConstructor.cpp \
   StackVector.cpp \
   StackConditional.cpp \
+  StackAggrInit.cpp \
   $(NULL)
 
 STACK_PASS_TESTCASES = \
   StackPlacementNewOK.cpp \
   $(NULL)
 
 OUTPARAMS_WARNING_TESTCASES = \
   e1.cpp \
@@ -116,16 +117,18 @@ STATIC_WARNING_TESTCASES = \
   $(NULL)
 
 STATIC_PASS_TESTCASES = \
   $(OUTPARAMS_PASS_TESTCASES) \
   $(STACK_PASS_TESTCASES) \
   $(FLOW_PASS_TESTCASES) \
   $(NULL)
 
+REQUIRES = xpcom
+
 include $(topsrcdir)/config/rules.mk
 
 # We want to compile each file and invert the result to ensure that
 # compilation failed.
 check:: \
   $(STATIC_FAILURE_TESTCASES:.cpp=.s-fail) \
   $(STATIC_WARNING_TESTCASES:.cpp=.s-warn) \
   $(STATIC_PASS_TESTCASES:.cpp=.s-pass)
@@ -137,23 +140,23 @@ check:: \
 	  exit 1; \
 	else \
 	  printf "ok.\n"; \
 	fi
 
 %.s-warn: %.cpp $(GLOBAL_DEPS) $(DEHYDRA_SCRIPTS)
 	@printf "Compiling $(<F) to check that the static-analysis script is checking properly..."
 	@if $(CCC) -Werror $(OUTOPTION)/dev/null -S $(COMPILE_CXXFLAGS) $(_VPATH_SRCS) >$(*F).errlog 2>&1; then \
-	  printf "fail:\nerror: compilation of $(<F) succeeded with -Werror. It shouldn't have!\n" \
+	  printf "fail:\nerror: compilation of $(<F) succeeded with -Werror. It shouldn't have!\n"; \
 	  exit 1; \
 	fi
 	@if $(CCC) $(OUTOPTION)/dev/null -S $(COMPILE_CXXFLAGS) $(_VPATH_SRCS) >$(*F).werrlog 2>&1; then \
 	  printf "ok.\n"; \
 	else \
-	  printf "fail:\nerror: compilation of $(<F) without -Werror failed. A warning should have been issued.\n" \
+	  printf "fail:\nerror: compilation of $(<F) without -Werror failed. A warning should have been issued.\n"; \
 	  exit 1; \
 	fi
 
 %.s-pass: %.cpp $(GLOBAL_DEPS) $(DEHYDRA_SCRIPTS)
 	@printf "Compiling $(<F) to check that the static-analysis script is checking properly..."
 	@if $(CCC) -Werror $(OUTOPTION)/dev/null -S $(COMPILE_CXXFLAGS) $(_VPATH_SRCS) >$(*F).errlog 2>&1; then \
 	  printf "ok.\n"; \
 	else \
new file mode 100644
--- /dev/null
+++ b/xpcom/tests/static-checker/StackAggrInit.cpp
@@ -0,0 +1,12 @@
+#include "nscore.h"
+#include "nsAutoPtr.h"
+
+class NS_STACK_CLASS A
+{
+  int i;
+};
+
+void Foo()
+{
+  nsAutoPtr<A> a(new A);
+}