Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions tools/clang/unittests/HLSL/DxilContainerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,27 @@
#include <atlfile.h>
#include <d3dcompiler.h>
#pragma comment(lib, "d3dcompiler.lib")
#if _MSC_VER >= 1920
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
#include <experimental/filesystem>
#else
#include <filesystem>
#endif

#if defined(_MSC_VER)
// MSVC removed <experimental/filesystem> starting in VS 2019 16.3 (_MSC_VER >= 1922)
#if _MSC_VER < 1922
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if _MSC_VER < 1922
#if (_MSC_VER >= 1920) && (_MSC_VER < 1922)

experimental::filesystem was enabled since version 1920, so it needs to be included in the check.

#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#else
#include <filesystem>
namespace fs = std::filesystem;
#endif
#elif defined(__has_include) && __has_include(<filesystem>) && \
(defined(__clang__) || !defined(__GNUC__) || __GNUC__ >= 8)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to check && \ (defined(__clang__) || !defined(__GNUC__) || __GNUC__ >= 8) why isn't just checking for the feature sufficient?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for GNUC >= 8: GCC 7 ships but doesn't actually define std::filesystem. Header exists, namespace doesn't -> compile error. GCC 8 is the first version where it really works.
For the defined(clang) check: Clang sets GNUC == 4, so the >= 8 check would wrongly reject it. The clause basically says "if it's Clang, skip the GCC version check."

#include <filesystem>
namespace fs = std::filesystem;
#else
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure which compiler this else case covers?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I consulted an AI, and basically it looks like really old compilers would be covered by this case:
GCC 5.3 – 7.x
Pre-2014 GCC / Clang without __has_include
Clang with an old libstdc++/libc++

are some examples.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even support compilers that old for building dxc? LLVM has a cut off. Not sure if DXC ever required a minimum compiler version.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GCC 8 came out in 2018, and I don't think we should support compilers older than that. I think you can remove the #elif`` condition and just fall back to #include `.

#endif

using namespace fs;

#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -72,8 +86,6 @@ using namespace std;
using namespace hlsl_test;
#ifdef _WIN32

using namespace std::experimental::filesystem;

static uint8_t MaskCount(uint8_t V) {
DXASSERT_NOMSG(0 <= V && V <= 0xF);
static const uint8_t Count[16] = {0, 1, 1, 2, 1, 2, 2, 3,
Expand Down