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 48919 - kmp_settings.cpp fails to compile on Windows with error C2131: expression did not evaluate to a constant
Summary: kmp_settings.cpp fails to compile on Windows with error C2131: expression did...
Status: RESOLVED FIXED
Alias: None
Product: OpenMP
Classification: Unclassified
Component: Runtime Library (show other bugs)
Version: unspecified
Hardware: PC Windows NT
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks: release-12.0.0
  Show dependency tree
 
Reported: 2021-01-28 03:28 PST by Hans Wennborg
Modified: 2021-01-29 22:22 PST (History)
3 users (show)

See Also:
Fixed By Commit(s): 7f5ad0e07162e0c19e569986ee37a17c147c9a27 074ad6de6fae


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hans Wennborg 2021-01-28 03:28:34 PST
in a VS 2019 x86 Native Tools Command Prompt

with llvmorg-12.0.0-rc1 checked out

cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PROJECTS="clang;openmp" ..\llvm
ninja omp

C:\src\llvm.monorepo\openmp\runtime\src\kmp_settings.cpp(3358): error C2131: expression did not evaluate to a constant
C:\src\llvm.monorepo\openmp\runtime\src\kmp_settings.cpp(3358): note: failure was caused by a read of a variable outside its lifetime
C:\src\llvm.monorepo\openmp\runtime\src\kmp_settings.cpp(3358): note: see usage of 'ntraits'


Bisection points to


commit 927af4b3c57681e623b8449fb717a447559358d0
Author: Nawrin Sultana <nawrin.sultana@intel.com>
Date:   Mon Nov 2 16:17:37 2020 -0600

    [OpenMP] Modify OMP_ALLOCATOR environment variable

    This patch sets the def-allocator-var ICV based on the environment variables
    provided in OMP_ALLOCATOR. Previously, only allowed value for OMP_ALLOCATOR
    was a predefined memory allocator. OpenMP 5.1 specification allows predefined
    memory allocator, predefined mem space, or predefined mem space with traits in
    OMP_ALLOCATOR. If an allocator can not be created using the provided environment
    variables, the def-allocator-var is set to omp_default_mem_alloc.

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

 openmp/runtime/src/kmp_settings.cpp       | 391 ++++++++++++++++++++++++------
 openmp/runtime/test/env/omp51_alloc_env.c |  31 +++
 2 files changed, 353 insertions(+), 69 deletions(-)
 create mode 100644 openmp/runtime/test/env/omp51_alloc_env.c



As of this morning the same error happens on the main branch too.
Comment 1 Hans Wennborg 2021-01-28 03:40:16 PST
> C:\src\llvm.monorepo\openmp\runtime\src\kmp_settings.cpp(3358): error C2131:
> expression did not evaluate to a constant
> C:\src\llvm.monorepo\openmp\runtime\src\kmp_settings.cpp(3358): note:
> failure was caused by a read of a variable outside its lifetime
> C:\src\llvm.monorepo\openmp\runtime\src\kmp_settings.cpp(3358): note: see
> usage of 'ntraits'

I think what MSVC might be trying to say in this convoluted way, is that it doesn't like

  omp_alloctrait_t traits[ntraits]

because ntraits is not constant, and so this would be a variable-length array which isn't support in C++ (though often allowed as an extension).

The fix would be to not use a VLA here.
Comment 2 Andrey Churbanov 2021-01-28 09:14:45 PST
I've posted the fix https://reviews.llvm.org/D95627 for review.
Comment 4 Hans Wennborg 2021-01-29 04:19:41 PST
(In reply to Andrey Churbanov from comment #3)
> Fixed by commit
> https://github.com/llvm/llvm-project/commit/
> 7f5ad0e07162e0c19e569986ee37a17c147c9a27.

Thanks! That seems to work on my machine.

Tom, can we merge this to the release branch?
Comment 5 Tom Stellard 2021-01-29 22:22:40 PST
Merged: 074ad6de6fae