[cfe-dev] [Patch] Add MallocAttr to new operator

Douglas Gregor dgregor at apple.com
Wed Aug 18 08:07:00 PDT 2010


On Aug 12, 2010, at 1:29 PM, Tom Jablin wrote:

> Hi,
> 
> Starting with revision 110175, there was a regression in clang where the return type of the new operator was not marked with noalias when there was an explicit declaration of the new operator. This is a problem since the <new> header explicitly declares the new operator. The <new> header is indirectly including through many other headers including <string> and <iostream>. I have enclosed a patch to add the MallocAttr to the new operator as long as -fassume-sane-operator-new is set.
> 
> Here is a simple test case:
> $ echo -e "#include <string>\nvoid foo(void) { delete[] new int[10]; }" | clang -x c++ - -emit-llvm -S -o - | grep declare.*Znam
> declare i8* @_Znam(i64)
> 
> after the patch:
> $ echo -e "#include <string>\nvoid foo(void) { delete[] new int[10]; }" | clang -x c++ - -emit-llvm -S -o - | grep declare.*Znam
> declare noalias i8* @_Znam(i64)

Thanks, committed as r111363 along with a version of the test above. In the future, it would help if you could include a test case in the patch that can go directly into the Clang test-suite.

	- Doug





More information about the cfe-dev mailing list