From 441cf1004620342ec8efb5b849abd4b89f0cf552 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Sat, 16 May 2009 23:27:50 +0000 Subject: [PATCH] Refactor address-of-void extension a bit so that it's more obviously correct. No functionality change, as far as I know. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71965 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExpr.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index a31a96488a..744b020986 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -4426,14 +4426,10 @@ QualType Sema::CheckAddressOfOperand(Expr *op, SourceLocation OpLoc) { NamedDecl *dcl = getPrimaryDecl(op); Expr::isLvalueResult lval = op->isLvalue(Context); - if (lval != Expr::LV_Valid) { // C99 6.5.3.2p1 + if (lval != Expr::LV_Valid && lval != Expr::LV_IncompleteVoidType) { + // C99 6.5.3.2p1 // The operand must be either an l-value or a function designator - if (op->getType()->isFunctionType()) { - // Function designator is valid - } else if (lval == Expr::LV_IncompleteVoidType) { - Diag(OpLoc, diag::ext_typecheck_addrof_void) - << op->getSourceRange(); - } else { + if (!op->getType()->isFunctionType()) { // FIXME: emit more specific diag... Diag(OpLoc, diag::err_typecheck_invalid_lvalue_addrof) << op->getSourceRange(); @@ -4481,6 +4477,13 @@ QualType Sema::CheckAddressOfOperand(Expr *op, SourceLocation OpLoc) { assert(0 && "Unknown/unexpected decl type"); } + if (lval == Expr::LV_IncompleteVoidType) { + // Taking the address of a void variable is technically illegal, but we + // allow it in cases which are otherwise valid. + // Example: "extern void x; void* y = &x;". + Diag(OpLoc, diag::ext_typecheck_addrof_void) << op->getSourceRange(); + } + // If the operand has type "type", the result has type "pointer to type". return Context.getPointerType(op->getType()); } -- 2.40.0