{"action":"reopened","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/14262","repository_url":"https://api.github.com/repos/dotnet/roslyn","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/14262/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/14262/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/14262/events","html_url":"https://github.com/dotnet/roslyn/issues/14262","id":180863418,"number":14262,"title":"Optimizing a conditional AND to a logical AND requires coercion","user":{"login":"hadibrais","id":5206180,"avatar_url":"https://avatars.githubusercontent.com/u/5206180?v=3","gravatar_id":"","url":"https://api.github.com/users/hadibrais","html_url":"https://github.com/hadibrais","followers_url":"https://api.github.com/users/hadibrais/followers","following_url":"https://api.github.com/users/hadibrais/following{/other_user}","gists_url":"https://api.github.com/users/hadibrais/gists{/gist_id}","starred_url":"https://api.github.com/users/hadibrais/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hadibrais/subscriptions","organizations_url":"https://api.github.com/users/hadibrais/orgs","repos_url":"https://api.github.com/users/hadibrais/repos","events_url":"https://api.github.com/users/hadibrais/events{/privacy}","received_events_url":"https://api.github.com/users/hadibrais/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":21,"created_at":"2016-10-04T11:03:00Z","updated_at":"2016-10-05T12:34:23Z","closed_at":null,"body":"**Version Used**:  \r\nVS 2015\r\n\r\n**Description**:\r\nSection III.1.1.2 of the Common Language Infrastructure (CLI) defines the **System.Boolean** type to be of size 1 byte where a bit pattern of all zeroes denotes **False** and any other bit pattern denotes **True**. Also it's a CLS type. On the hand, the C# specification states in 4.1.8 that the **bool** type is an alias to **System.Boolean** and represents two values, **True** and **False**, without saying anything about their implementation. This is all fine. The problem occurs when the C# compiler assumes that **True** is always represented as 0x01, which violates the CLS.\r\n\r\n**Steps to Reproduce**:\r\nConsider the following method:\r\n\r\n```\r\npublic static bool And(bool a, bool b)\r\n{\r\n        return a && b;\r\n}\r\n```\r\n\r\n**Expected Behavior**:\r\nThe compiler can either emit the code that implements the short-circuiting conditional AND or emits instructions to coerce both operands to the bit patterns 0x00 for **False** and 0x01 for **True** and use the logical (bitwise) AND CIL instruction.\r\n\r\n**Actual Behavior**:\r\nThe compiler emits the following instructions:\r\n\r\n```\r\nldarg.0\r\nldarg.1\r\nand\r\n```\r\n\r\nIt applies the logical AND instruction on the arguments without coercing them. If both arguments were **True** with complementary bit patterns (which is CLS-compliant), the result would be **False,** which is incorrect.\r\n\r\n**Additional Information**:\r\n\r\nBy very quickly going through the Roslyn code, I think that this transformation is implemented [here](https://github.com/dotnet/roslyn/blob/master/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_BinaryOperator.cs#L241), but I'm not sure. It seems that in Roslyn, the conditional AND is called the Logical AND and the Logical AND is called the Bool AND.\r\n"}}
{"actor":{"display_login":"hadibrais"}}