From a39c64d044f8014a631ac802c8a20ddce9c57822 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 15 Apr 2015 21:50:06 +0000 Subject: [PATCH] Make __declspec(selectany) turn variable declartions into definitions. Fixes PR23242. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235046 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Decl.cpp | 4 ++-- test/CodeGen/ms-declspecs.c | 4 ++++ test/CodeGen/ms-declspecs.cpp | 13 +++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 test/CodeGen/ms-declspecs.cpp diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 2ae73de507..349b7b43d1 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -1926,14 +1926,14 @@ VarDecl::DefinitionKind VarDecl::isThisDeclarationADefinition( getTemplateSpecializationKind() != TSK_ExplicitSpecialization) return DeclarationOnly; - if (hasExternalStorage()) + if (!hasAttr() && hasExternalStorage()) return DeclarationOnly; // [dcl.link] p7: // A declaration directly contained in a linkage-specification is treated // as if it contains the extern specifier for the purpose of determining // the linkage of the declared name and whether it is a definition. - if (isSingleLineLanguageLinkage(*this)) + if (!hasAttr() && isSingleLineLanguageLinkage(*this)) return DeclarationOnly; // C99 6.9.2p2: diff --git a/test/CodeGen/ms-declspecs.c b/test/CodeGen/ms-declspecs.c index 328fc835d3..985c227faa 100644 --- a/test/CodeGen/ms-declspecs.c +++ b/test/CodeGen/ms-declspecs.c @@ -5,6 +5,10 @@ const __declspec(selectany) int x2 = 2; // CHECK: @x1 = weak_odr global i32 1, comdat, align 4 // CHECK: @x2 = weak_odr constant i32 2, comdat, align 4 +// selectany turns extern variable declarations into definitions. +extern __declspec(selectany) int x3; +// CHECK: @x3 = weak_odr global i32 0, comdat, align 4 + struct __declspec(align(16)) S { char x; }; diff --git a/test/CodeGen/ms-declspecs.cpp b/test/CodeGen/ms-declspecs.cpp new file mode 100644 index 0000000000..f77c7cb891 --- /dev/null +++ b/test/CodeGen/ms-declspecs.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -triple i386-pc-win32 %s -emit-llvm -fms-compatibility -o - | FileCheck %s + +// selectany turns extern "C" variable declarations into definitions. +extern __declspec(selectany) int x1; +extern "C" __declspec(selectany) int x2; +extern "C++" __declspec(selectany) int x3; +extern "C" { +__declspec(selectany) int x4; +} +// CHECK: @"\01?x1@@3HA" = weak_odr global i32 0, comdat, align 4 +// CHECK: @x2 = weak_odr global i32 0, comdat, align 4 +// CHECK: @"\01?x3@@3HA" = weak_odr global i32 0, comdat, align 4 +// CHECK: @x4 = weak_odr global i32 0, comdat, align 4 -- 2.40.0