Skip to content

ClangImporter: synchronize clang and Swift #35290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
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
25 changes: 22 additions & 3 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,28 @@ importer::getNormalInvocationArguments(
});
}

invocationArgStrs.insert(invocationArgStrs.end(), {
EnableCXXInterop ? "-std=gnu++17" : "-std=gnu11",
});
{
const clang::LangStandard &stdcxx =
#if defined(CLANG_DEFAULT_STD_CXX)
*clang::LangStandard::getLangStandardForName(CLANG_DEFAULT_STD_CXX);
#else
clang::LangStandard::getLangStandardForKind(
clang::LangStandard::lang_gnucxx14);
#endif

const clang::LangStandard &stdc =
#if defined(CLANG_DEFAULT_STD_C)
*clang::LangStandard::getLangStandardForName(CLANG_DEFAULT_STD_C);
#else
clang::LangStandard::getLangStandardForKind(
clang::LangStandard::lang_gnu11);
#endif

invocationArgStrs.insert(invocationArgStrs.end(), {
(Twine("-std=") + StringRef(EnableCXXInterop ? stdcxx.getName()
: stdc.getName())).str()
});
}

// Set C language options.
if (triple.isOSDarwin()) {
Expand Down
3 changes: 2 additions & 1 deletion test/Interop/Cxx/static/constexpr-static-member-var.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RUN: %empty-directory(%t)
// RUN: %target-clang -c %S/Inputs/static-member-var.cpp -I %S/Inputs -o %t/static-member-var.o -std=c++17
// RUN: %target-build-swift %s -I %S/Inputs -o %t/statics %t/static-member-var.o -Xfrontend -enable-cxx-interop
// NOTE: we must use `-O` here to ensure that the constexpr value is inlined and no undefined reference remains.
// RUN: %target-build-swift -O %s -I %S/Inputs -o %t/statics %t/static-member-var.o -Xfrontend -enable-cxx-interop
// RUN: %target-codesign %t/statics
// RUN: %target-run %t/statics
//
Expand Down
5 changes: 4 additions & 1 deletion test/Interop/Cxx/static/static-member-var-irgen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
//to depend on external definitions. However, our code generation pattern loads
//the value dynamically. Instead, we should inline known constants. That would
//allow Swift code to even read the value of WithIncompleteStaticMember::notDefined.
// CHECK: @{{_ZN25WithConstexprStaticMember13definedInlineE|"\?definedInline@WithConstexprStaticMember@@2HB"}} = linkonce_odr {{(dso_local )?}}constant i32 139, {{(comdat, )?}}align 4
// NOTE: we allow both available_externally and linkonce_odr as there are
// differences in between MSVC and itanium model semantics where the constexpr
// value is emitted into COMDAT.
// CHECK: @{{_ZN25WithConstexprStaticMember13definedInlineE|"\?definedInline@WithConstexprStaticMember@@2HB"}} = {{available_externally|linkonce_odr}} {{(dso_local )?}}constant i32 139, {{(comdat, )?}}align 4

import StaticMemberVar

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#ifndef TEST_INTEROP_CXX_TEMPLATES_INPUTS_CLASS_TEMPLATE_NON_TYPE_PARAMETER_H
#define TEST_INTEROP_CXX_TEMPLATES_INPUTS_CLASS_TEMPLATE_NON_TYPE_PARAMETER_H

template<class T, auto Size>
#if defined(__clang__)
using size_t = __SIZE_TYPE__;
#endif

template<class T, size_t Size>
struct MagicArray {
T t[Size];
};
Expand Down