Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
2f98b36c
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
2f98b36c
编写于
9月 27, 2018
作者:
J
Jared Parsons
提交者:
GitHub
9月 27, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #29097 from alrz/issue29092
Handle mixed initializer style with initblk
上级
4ffecf04
759e37b2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
83 addition
and
0 deletion
+83
-0
src/Compilers/CSharp/Portable/CodeGen/EmitStackAllocInitializer.cs
...lers/CSharp/Portable/CodeGen/EmitStackAllocInitializer.cs
+5
-0
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStackAllocInitializerTests.cs
...rp/Test/Emit/CodeGen/CodeGenStackAllocInitializerTests.cs
+78
-0
未找到文件。
src/Compilers/CSharp/Portable/CodeGen/EmitStackAllocInitializer.cs
浏览文件 @
2f98b36c
...
...
@@ -33,6 +33,11 @@ private void EmitStackAllocInitializers(TypeSymbol type, BoundArrayInitializatio
if
(
data
.
All
(
datum
=>
datum
==
data
[
0
]))
{
_builder
.
EmitStackAllocBlockInitializer
(
data
,
inits
.
Syntax
,
emitInitBlock
:
true
,
_diagnostics
);
if
(
initializationStyle
==
ArrayInitializerStyle
.
Mixed
)
{
EmitElementStackAllocInitializers
(
elementType
,
initExprs
,
includeConstants
:
false
);
}
}
else
if
(
elementType
.
SpecialType
.
SizeInBytes
()
==
1
)
{
...
...
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStackAllocInitializerTests.cs
浏览文件 @
2f98b36c
...
...
@@ -2,6 +2,7 @@
using
Microsoft.CodeAnalysis.CSharp.Test.Utilities
;
using
Microsoft.CodeAnalysis.Test.Utilities
;
using
Roslyn.Test.Utilities
;
using
Xunit
;
namespace
Microsoft.CodeAnalysis.CSharp.UnitTests
...
...
@@ -9,6 +10,83 @@ namespace Microsoft.CodeAnalysis.CSharp.UnitTests
[
CompilerTrait
(
CompilerFeature
.
StackAllocInitializer
)]
public
class
CodeGenStackAllocInitializerTests
:
CompilingTestBase
{
[
Fact
]
[
WorkItem
(
29092
,
"https://github.com/dotnet/roslyn/issues/29092"
)]
public
void
TestMixedWithInitBlock
()
{
var
text
=
@"
using System;
class Program
{
static void Main(string[] args)
{
MakeBlock(1, 2, 3);
}
static unsafe void MakeBlock(int a, int b, int c)
{
int* ptr = stackalloc int[]
{
0, 0, 0, a, b, c
};
PrintBytes(ptr, 6);
}
static unsafe void PrintBytes(int* ptr, int count)
{
for (int i = 0; i < count; i++)
{
Console.Write(ptr[i]);
}
}
}"
;
CompileAndVerify
(
text
,
parseOptions
:
TestOptions
.
Regular
.
WithLanguageVersion
(
LanguageVersion
.
CSharp7_3
),
options
:
TestOptions
.
UnsafeReleaseExe
,
expectedOutput
:
"000123"
,
verify
:
Verification
.
Fails
).
VerifyIL
(
"Program.MakeBlock"
,
@"{
// Code size 42 (0x2a)
.maxstack 4
IL_0000: ldc.i4.s 24
IL_0002: conv.u
IL_0003: localloc
IL_0005: dup
IL_0006: ldc.i4.0
IL_0007: ldc.i4.s 24
IL_0009: initblk
IL_000b: dup
IL_000c: ldc.i4.3
IL_000d: conv.i
IL_000e: ldc.i4.4
IL_000f: mul
IL_0010: add
IL_0011: ldarg.0
IL_0012: stind.i4
IL_0013: dup
IL_0014: ldc.i4.4
IL_0015: conv.i
IL_0016: ldc.i4.4
IL_0017: mul
IL_0018: add
IL_0019: ldarg.1
IL_001a: stind.i4
IL_001b: dup
IL_001c: ldc.i4.5
IL_001d: conv.i
IL_001e: ldc.i4.4
IL_001f: mul
IL_0020: add
IL_0021: ldarg.2
IL_0022: stind.i4
IL_0023: ldc.i4.6
IL_0024: call ""void Program.PrintBytes(int*, int)""
IL_0029: ret
}"
);
}
[
Fact
]
public
void
TestUnmanaged_Pointer
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录