[all-commits] [llvm/llvm-project] e6d305: Add support of Windows Trace Logging macros

Richard Dzenis via All-commits all-commits at lists.llvm.org
Mon Sep 4 07:54:57 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e6d305e64fd39f0199b79d19dbc0d012efd83259
      https://github.com/llvm/llvm-project/commit/e6d305e64fd39f0199b79d19dbc0d012efd83259
  Author: Richard Dzenis <dzenis at richard.lv>
  Date:   2023-09-04 (Mon, 04 Sep 2023)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/Sema/Sema.h
    M clang/lib/AST/ExprConstant.cpp
    M clang/lib/Sema/Sema.cpp
    M clang/lib/Sema/SemaExpr.cpp
    M clang/test/Sema/ms_predefined_expr.cpp

  Log Message:
  -----------
  Add support of Windows Trace Logging macros

Consider the following code:

    #include <windows.h>
    #include <TraceLoggingActivity.h>
    #include <TraceLoggingProvider.h>
    #include <winmeta.h>

    TRACELOGGING_DEFINE_PROVIDER(
        g_hMyComponentProvider,
        "SimpleTraceLoggingProvider",
        // {0205c616-cf97-5c11-9756-56a2cee02ca7}
        (0x0205c616,0xcf97,0x5c11,0x97,0x56,0x56,0xa2,0xce,0xe0,0x2c,0xa7));

    void test()
    {
        TraceLoggingFunction(g_hMyComponentProvider);
    }

    int main()
    {
        TraceLoggingRegister(g_hMyComponentProvider);
        test();
        TraceLoggingUnregister(g_hMyComponentProvider);
    }

It compiles with MSVC, but clang-cl reports an error:

    C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\shared/TraceLoggingActivity.h(377,30): note: expanded from macro '_tlgThisFunctionName'
    #define _tlgThisFunctionName __FUNCTION__
                                 ^
    .\tl.cpp(14,5): error: cannot initialize an array element of type 'char' with an lvalue of type 'const char[5]'
        TraceLoggingFunction(g_hMyComponentProvider);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The second commit is not needed to support above code, however, during isolated tests in ms_predefined_expr.cpp
I found that MSVC accepts code with constexpr, whereas clang-cl does not.
I see that in most places PredefinedExpr is supported in constant evaluation, so I didn't wrap my code with ``if(MicrosoftExt)``.

Reviewed By: cor3ntin

Differential Revision: https://reviews.llvm.org/D158591




More information about the All-commits mailing list