LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 23071 - MS-compatibility: XAudio2.h fails to compile due to spaces in GUID
Summary: MS-compatibility: XAudio2.h fails to compile due to spaces in GUID
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: Frontend (show other bugs)
Version: trunk
Hardware: PC All
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-30 09:36 PDT by jonathan.sauer
Modified: 2015-04-17 07:51 PDT (History)
4 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jonathan.sauer 2015-03-30 09:36:28 PDT
The following code (excerpted from Microsoft's DirectX header XAudio2.h) fails to compile with Windows compatibility:

#define DECLSPEC_UUID_WRAPPER(x) __declspec(uuid(#x))

#define DEFINE_CLSID(className, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
  class DECLSPEC_UUID_WRAPPER(l##-##w1##-##w2##-##b1##b2##-##b3##b4##b5##b6##b7##b8) className

DEFINE_CLSID(XAudio2, 5a508685, a254, 4fba, 9b, 82, 9a, 24, b0, 03, 06, af);
//DEFINE_CLSID(XAudio2,5a508685,a254,4fba,9b,82,9a,24,b0,03,06,af);


This results in: 

% clang++ -fms-extensions -Wno-invalid-token-paste -c clang.cpp 
clang.cpp:6:1: error: uuid attribute contains a malformed GUID
DEFINE_CLSID(XAudio2, 5a508685, a254, 4fba, 9b, 82, 9a, 24, b0, 03, 06, af);
^
clang.cpp:4:8: note: expanded from macro 'DEFINE_CLSID'
        class DECLSPEC_UUID_WRAPPER(l##-##w1##-##w2##-##b1##b2##-##b3##b4##b5##b6##b7##b8) className
              ^
clang.cpp:1:50: note: expanded from macro 'DECLSPEC_UUID_WRAPPER'
#define DECLSPEC_UUID_WRAPPER(x) __declspec(uuid(#x))
                                                 ^
<scratch space>:16:1: note: expanded from here
"5a508685- a254- 4fba- 9b82- 9a24b00306af"
^
1 error generated.


When using the commented DEFINE_CLSID-line without the spaces, the code compiles successfully.
Comment 1 Reid Kleckner 2015-03-30 11:41:18 PDT
Yeah, I see the issue.

I can't find this GUID in the Win 7.0A SDK, the Win 8.0 SDK, or the Win 8.1 SDK. Where exactly did you encounter this issue? I don't want to add another compatibility hack unless it's a bug in a recent, widely used header.
Comment 2 Reid Kleckner 2015-03-30 11:42:49 PDT
If this is just a problem in the 2010 June Direct X SDK, then I'd rather encourage people to migrate to the Win8 SDK than add this hack. The xaudio2.h header in the Win 8 SDK doesn't appear to have this problem.
Comment 3 jonathan.sauer 2015-03-30 12:47:43 PDT
>Where exactly did you encounter this issue?

In the copy of the DirectX headers in the Unreal Engine which seem to be the June 2010 SDK. I noticed that a recent commit there included a workaround for clang's behavior[*] and thought I'd file a bug report.

[*] https://github.com/EpicGames/UnrealEngine/commit/701ad40823134d909081d70e83dea3a149a355ed (I'm afraid it's a private repository; you'll need to register an account at Epic Games to get access)
Comment 4 Mike Fricker 2015-03-30 13:18:46 PDT
Hey this is Mike Fricker at Epic.  

I've been tracking the progress of Clang  on Windows and updating Unreal Engine to support that as a build target as a background project.  As of last weekend the Unreal Editor is now able to be fully compiled on Windows under Clang (requires LLVM r231657.)

Upgrading to a newer DirectX SDK is not really an option.  There are a slew of PC titles that use the June 2010 DirectX SDK specifically for DirectX 9 support on Windows XP and Windows 7, which is not available in the newer SDKs.

The Unreal Engine codebase is actually an excellent test case for LLVM on all platforms.  There are actually a number of other issues we've observed and can reproduce.  I'll work with the team to get those entered into your database.


--Mike
Comment 5 jonathan.sauer 2015-03-30 13:34:52 PDT
Honestly I would have thought that leading and trailing spaces were trimmed from arguments during macro expansion.

Another thing: This location in the preprocessor backtrace looks a bit weird:

| <scratch space>:16:1


(In reply to comment #4)
> I'll work with the team to get those entered into your database.

Please do!
Comment 6 Reid Kleckner 2015-03-30 13:48:55 PDT
OK, if the June 2010 SDK is still super widely used, then we probably want to do something here.
Comment 7 Will Wilson 2015-04-17 07:51:49 PDT
Fixed by r235186: [MSVC] Mimic MSVC whitespace collapse for incompatible token pasting

The workaround is simple but a little ugly. Let me know if there's any fallout.