[MS] Fix double evaluation of MSVC builtin arguments
authorReid Kleckner <rnk@google.com>
Tue, 24 Nov 2020 22:48:05 +0000 (14:48 -0800)
committerReid Kleckner <rnk@google.com>
Wed, 25 Nov 2020 19:55:01 +0000 (11:55 -0800)
commit3bd06727267184223464f11d4e2470048ac40cb1
treedf92fc8258dc7dc0143776182abf09e7701d5137
parenta0156356296b54dc071405332a517695b1881bc1
[MS] Fix double evaluation of MSVC builtin arguments

This code got quite twisted because we consider some MSVC builtins to be
target agnostic, and some to be target specific. Target specific
intrinsics have a pattern of doing up-front argument evaluation, while
general intrinsics do not evaluate their arguments up front. As we tried
to share codepaths between the target-specific and target-agnostic
handling, we ended up doing double evaluation.

Instead, have each target handle MSVC intrinsics consistently before up
front argument evaluation. This requires passing less data around and is
more consistent with target independent intrinsic handling.

See D50979 for past examples of this bug. I noticed this while looking
into adding some more intrinsics.

Differential Revision: https://reviews.llvm.org/D92061
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/test/CodeGen/ms-intrinsics.c