This is an archive of the discontinued LLVM Phabricator instance.

[MSVC] Improved __noop support (https://llvm.org/bugs/show_bug.cgi?id=14081)
Needs ReviewPublic

Authored by ili.filippov on Apr 13 2015, 4:56 AM.

Details

Reviewers
rnk
rsmith
Summary

noop is declared with manually checked arguments ("t") that prevents any checking of argument completeness. noop can be called with void arguments now.
It is declared that noop has constant zero return value. So noop can be assigned as a pointer now.
Special flag is added which indicates that parsing is inside noop expression. Functions aren't marked as referenced if they are noop parameters. This prevents from template instantiation of function that is used only in __noop expression.

This behavior is the same as MS compiler behavior.

Diff Detail

Event Timeline

ili.filippov retitled this revision from to [MSVC] Improved __noop support (https://llvm.org/bugs/show_bug.cgi?id=14081).
ili.filippov updated this object.
ili.filippov edited the test plan for this revision. (Show Details)
ili.filippov added reviewers: rsmith, rnk.
ili.filippov added a subscriber: Unknown Object (MLST).
rnk edited edge metadata.Apr 14 2015, 2:12 PM

I'm concerned that there are other ways for code inside __noop() to trigger template instantiation, which will cause us to do semantic analysis in a weird state.

lib/Sema/SemaExpr.cpp
13244

s/match/mark/

13248

Why do we need to mark non-FunctionDecls referenced? Surely they can trigger template instantiation of other function decls.

13248

Can this just be if (InsideNoop) return; at the beginning of the function?

test/CodeGen/builtin-ms-noop.cpp
37

This test will not pass in NDEBUG mode because the IR names are skipped. You can either pattern match the alloca, or you can store to a global.

chatur01 added inline comments.
test/Sema/builtin-ms-noop-errors.cpp
17

I find checking this note weird. I know __noop is defined as taking ... from the Builtins.def file, but ASTContext::GetBuiltinType decides to ignore it and generate the empty argument list instead.

rsmith added inline comments.Apr 14 2015, 4:04 PM
lib/Parse/ParseExpr.cpp
1473–1478

Code in Parse shouldn't be inspecting the AST like this. If you really need different parse rules for the argument of __noop, maybe make it a keyword rather than a builtin?

1480–1481

Can you enter an unevaluated context here rather than inventing a new sort of context for this case? Global state in Sema doesn't seem like the right way to handle this -- if you trigger an instantiation from within this context, you should not instantiate the template in noop mode (it might end up being used outside noop mode too).

ili.filippov edited edge metadata.

Minor fixes of test and MarkDeclRefReferenced function.

This is a kind reminder to review the patch.

lib/Parse/ParseExpr.cpp
1473–1478

Firstly I tried to make noop as a separate keyword however noop has a builtin behavior in 95% cases. For example noop will be a normal variable after "int noop;" declaration. I suppose that it will be inefficient to detect all these cases for a new key-word.

1480–1481

Entering unevaluated context doesn’t prevent from template instantiation here. Global state points that we are inside __noop parsing now.

lib/Sema/SemaExpr.cpp
13248

Non-FunctionDecls are marked as referenced because this prevents warnings about unused variables

test/Sema/builtin-ms-noop-errors.cpp
17

This patch doesn’t influence on this. I simply added this case (error + note) in a test. Deleted them.

rnk added a comment.Jul 27 2015, 11:07 AM

I don't think you've addressed Richard's concerns convincingly. He feels that having more Sema-global contexts is the wrong way to go, and if this is the cost of more accurate __noop support, then maybe it's not worth it.