LLVM 8.0 strdup, strndup TestHarness_c.cpp

80 views
Skip to first unread message

James Grenning

unread,
Nov 29, 2016, 1:51:29 PM11/29/16
to cpputest

Hi All

The current repo is complaining about strdup and strndup during the cpputest build on a mac with LLVM.

Remove TestHarness_c.cpp and it builds fine.

$ make

/Applications/Xcode.app/Contents/Developer/usr/bin/make  all-am

g++ -DHAVE_CONFIG_H -I. -I..   -include ../include/CppUTest/MemoryLeakDetectorMallocMacros.h -I ../include     -include ../include/CppUTest/MemoryLeakDetectorNewMacros.h  -Wno-c++14-compat -Wno-c++11-long-long -Wno-long-long -Weverything -Wall -Wextra -Wshadow -Wswitch-default -Wswitch-enum -Wconversion -pedantic -Wsign-conversion -Woverloaded-virtual -Wno-disabled-macro-expansion -Wno-padded -Wno-reserved-id-macro -Wno-keyword-macro -Wno-global-constructors -Wno-exit-time-destructors -Wno-weak-vtables -Wno-old-style-cast   -g -O2 -MT src/CppUTest/lib_libCppUTest_a-CommandLineArguments.o -MD -MP -MF src/CppUTest/.deps/lib_libCppUTest_a-CommandLineArguments.Tpo -c -o src/CppUTest/lib_libCppUTest_a-CommandLineArguments.o `test -f 'src/CppUTest/CommandLineArguments.cpp' || echo '../'`src/CppUTest/CommandLineArguments.cpp

In file included from <built-in>:337:

In file included from <command line>:3:

In file included from ./../include/CppUTest/MemoryLeakDetectorNewMacros.h:32:

In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:610:

In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstring:61:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/string.h:117:7: error:

      expected parameter declarator

char    *strdup(const char *__s1);

        ^

./../include/CppUTest/MemoryLeakDetectorMallocMacros.h:40:51: note: expanded

     from macro 'strdup'

#define strdup(str) cpputest_strdup_location(str, __FILE__, __LINE__)

                                                 ^

<scratch space>:421:1: note: expanded from here

"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/De...

^

In file included from <built-in>:337:

In file included from <command line>:3:

In file included from ./../include/CppUTest/MemoryLeakDetectorNewMacros.h:32:

In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:610:

In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstring:61:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/string.h:117:7: error:

      expected ')'

./../include/CppUTest/MemoryLeakDetectorMallocMacros.h:40:51: note: expanded

     from macro 'strdup'

#define strdup(str) cpputest_strdup_location(str, __FILE__, __LINE__)

                                                 ^

<scratch space>:421:1: note: expanded from here

"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/De...

^

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/string.h:117:7: note:

      to match this '('

./../include/CppUTest/MemoryLeakDetectorMallocMacros.h:40:45: note: expanded

     from macro 'strdup'

#define strdup(str) cpputest_strdup_location(str, __FILE__, __LINE__)

                                           ^

In file included from <built-in>:337:

In file included from <command line>:3:

In file included from ./../include/CppUTest/MemoryLeakDetectorNewMacros.h:32:

In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:610:

In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstring:61:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/string.h:117:7: error:

      conflicting types for 'cpputest_strdup_location'

char    *strdup(const char *__s1);

        ^

./../include/CppUTest/MemoryLeakDetectorMallocMacros.h:40:21: note: expanded

     from macro 'strdup'

#define strdup(str) cpputest_strdup_location(str, __FILE__, __LINE__)

                   ^

./../include/CppUTest/MemoryLeakDetectorMallocMacros.h:25:14: note: previous

     declaration is here

extern char* cpputest_strdup_location(const char* str, const char* file...

            ^

In file included from <built-in>:337:

In file included from <command line>:3:

In file included from ./../include/CppUTest/MemoryLeakDetectorNewMacros.h:32:

In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:610:

In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstring:61:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/string.h:132:7: error:

      expected parameter declarator

char    *strndup(const char *__s1, size_t __n) __OSX_AVAILABLE_STARTING(...

        ^

./../include/CppUTest/MemoryLeakDetectorMallocMacros.h:41:59: note: expanded

     from macro 'strndup'

#define strndup(str, n) cpputest_strndup_location(str, n, __FILE__, __LINE__)

                                                         ^

<scratch space>:421:1: note: expanded from here

"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/De...

^

In file included from <built-in>:337:

In file included from <command line>:3:

In file included from ./../include/CppUTest/MemoryLeakDetectorNewMacros.h:32:

In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:610:

In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstring:61:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/string.h:132:7: error:

      expected ')'

./../include/CppUTest/MemoryLeakDetectorMallocMacros.h:41:59: note: expanded

     from macro 'strndup'

#define strndup(str, n) cpputest_strndup_location(str, n, __FILE__, __LINE__)

                                                         ^

<scratch space>:421:1: note: expanded from here

"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/De...

^

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/string.h:132:7: note:

      to match this '('

./../include/CppUTest/MemoryLeakDetectorMallocMacros.h:41:50: note: expanded

     from macro 'strndup'

#define strndup(str, n) cpputest_strndup_location(str, n, __FILE__, __LINE__)

                                                ^

In file included from <built-in>:337:

In file included from <command line>:3:

In file included from ./../include/CppUTest/MemoryLeakDetectorNewMacros.h:32:

In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:610:

In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstring:61:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/string.h:132:7: error:

      conflicting types for 'cpputest_strndup_location'

char    *strndup(const char *__s1, size_t __n) __OSX_AVAILABLE_STARTING(...

        ^

./../include/CppUTest/MemoryLeakDetectorMallocMacros.h:41:25: note: expanded

     from macro 'strndup'

#define strndup(str, n) cpputest_strndup_location(str, n, __FILE__, __LINE__)

                       ^

./../include/CppUTest/MemoryLeakDetectorMallocMacros.h:26:14: note: previous

     declaration is here

extern char* cpputest_strndup_location(const char* str, size_t n, const ...

            ^

6 errors generated.

make[1]: *** [src/CppUTest/lib_libCppUTest_a-CommandLineArguments.o] Error 1

make: *** [all] Error 2




Felipe Lavratti

unread,
Nov 30, 2016, 1:32:24 AM11/30/16
to cpputest
Believe I located the problem: its the famous conflict of malloc/new/strdup replacements and the standard headers.

By the Jame's compiler output, I see that Mac header file `<memory>` does includes the `<string.h>` file, this is different from every other compiler tested by the CI server.
And `MemoryLeakDetectorNewMacros.h` includes `<memory>` at line 32, which brings the conflict because `MemoryLeakDetectorMallocMacros.h` has already been included by the command line.

Two questions:

1) Can we add a Mac build in the CI?
2) Why do we have two headers? (`MemoryLeakDetectorMallocMacros.h` in the `MemoryLeakDetectorNewMacros.h`) Shouldn't we merge both and guard C++ code with `#ifdef __cplusplus`? It would simplify, the user code would have to include only one file via `-include` command line, and we can elegantly solve the llvm bug by selecting the order of each inclusion.

I did two fix proposals in my fork: https://github.com/felipe-lavratti/cpputest

1) Branch name llvm_strdup_bug_proposal_1
In this patch I fixed by adding #undefs and #includes on the `MemoryLeakDetectorNewMacros,h`
Diff view: https://github.com/felipe-lavratti/cpputest/compare/master...felipe-lavratti:llvm_strdup_bug_proposal_1

2) Branch name llvm_strdup_bug_proposal_2
Here I merged both headers as mentioned before.
Diff view: https://github.com/felipe-lavratti/cpputest/compare/master...felipe-lavratti:llvm_strdup_bug_proposal_2

James, would you mind checking out any or both of the branches in my fork and run a build on it?

Let me know wicth proposal you prefer so I can improve the comments and create a PR.

Thanks!

James Grenning

unread,
Dec 1, 2016, 5:25:06 AM12/1/16
to cpputest

Hi Felipe

Thanks for the prompt action. Unfortunately this is not on my computer. It is on someone's computer in my training class. I did not realize the problem is only in the example code build. So there is no problem with the cpputest buildLVM 8.0. Sorry I did not understand the problem better.

thanks again, James


James Grenning - Author of TDD for Embedded C - wingman-sw.com/tddec
wingman-sw.com
wingman-sw.com/blog
twitter.com/jwgrenning
facebook.com/wingman.sw
wingman software

--
You received this message because you are subscribed to the Google Groups "cpputest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Felipe Lavratti

unread,
Dec 1, 2016, 9:43:23 AM12/1/16
to cpputest
You're welcome James,

Still I got very surprised about the <strings.h> being included by <memory> in the LLVM and I'd like to do some double checking here, but I have no Mac machine right now. If anybody has a Mac and is willing to do some helping, please, download, build and send us the log of these three branches of my cpputest fork?

1) master
2) llvm_strdup_bug_proposal_1
3) llvm_strdup_bug_proposal_2
The repository path: g...@github.com:felipe-lavratti/cpputest.git

Thank you very much in advance :)

Felipe Lavratti

unread,
Dec 1, 2016, 1:43:33 PM12/1/16
to cpputest
A friend of mine helped us running these tests on his Mac. The problem you pointed, James, has been confirmed on my branch master (a few commits behind officials, but this is the place where `strdup` and `strndup` support was added), and both proposals branches fixed it. Macs have different headers from Linux and Windows boxes.

Find attached the build logs.

@Bas and Mainteners, it's up to you to choose which proposal we should merge, or recommend a third solution if you'd like.

Best,
Fanl

buildlogs.zip

Bas Vodde

unread,
Dec 4, 2016, 10:55:52 PM12/4/16
to cppu...@googlegroups.com

Hi,

I don’t think merging the files would be a good idea, so proposal #1.

However, the my_strlen doesn’t sound like an exciting name.

How can we add a Mac build to the CI?

Bas

Felipe Lavratti

unread,
Dec 5, 2016, 8:04:16 AM12/5/16
to cpputest
Hi Bas!

How do you feel about using the SimpleString::StrLen in the TestHarness_c.cpp file? Or is it better to stick with a local static strlen, if so, can you suggest me a better naming?

I've read on Travis website that they support OSx Builds, I'm gonna add a couple of osx builds (cmake and autotools) and make a PR, that we expect will fail since strdup fix hasn't been pushed yet :)

Felipe Lavratti

unread,
Dec 5, 2016, 3:15:38 PM12/5/16
to cpputest
@Bas,

I am implementing MAC builds in the Travis, on my fork, and a test of the extension is failing.


This is the log:

====================================

CppUTest 3.8: ./test-suite.log

====================================

# TOTAL: 2

# PASS: 1

# SKIP: 0

# XFAIL: 0

# FAIL: 1

# XPASS: 0

# ERROR: 0

.. contents:: :depth: 2

FAIL: CppUTestExtTests

======================

..................................................

..................................................

..................................................

..................................................

..................................................

..................................................

..................................................

.......!..........................................

.....................!

../tests/CppUTestExt/IEEE754PluginTest.cpp:122: error: Failure in TEST(FE__with_Plugin, should_not_fail_again_when_test_has_already_failed)

CHECK(IEEE754ExceptionsPlugin::checkIeee754OverflowExceptionFlag()) failed

............................

....

Errors (1 failures, 454 tests, 452 ran, 1411 checks, 2 ignored, 0 filtered out, 78 ms)

FAIL CppUTestExtTests (exit status: 1)


This is the job:
https://travis-ci.org/felipe-lavratti/cpputest/jobs/181419754

As soon I get all OSx jobs to pass I'll create the PR for the OSx CI and strdup fix on OSx.

Bas Vodde

unread,
Dec 6, 2016, 12:18:53 AM12/6/16
to cppu...@googlegroups.com

Hi,

Thanks!

Didn’t know travis now also supports Mac. That is good news!

Bas

Felipe Lavratti

unread,
Dec 6, 2016, 7:40:43 AM12/6/16
to cppu...@googlegroups.com
Well, I forgot to ask: Can you help-me with that test failing? I dunno
what's that extension is supposed to do.
> You received this message because you are subscribed to a topic in the
> Google Groups "cpputest" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/cpputest/0l2MrXLJPSs/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
Skype: felipeanl

Bas Vodde

unread,
Dec 6, 2016, 6:53:54 PM12/6/16
to cppu...@googlegroups.com
Answered via github.

Bas
Reply all
Reply to author
Forward
0 new messages