Short answer, for last-minute upgrades the original fare class not the upgraded one will be credited.
Here is the relevant section of Aeroplan T&C's:
Terms and Conditions for Accumulation
™ Air Canada Altitude is a Trademark of Air Canada
1. Aeroplan Miles will be credited to the Aeroplan account of the traveller, regardless of who pays for the ticket.
2. Aeroplan Miles will be credited for qualifying travel flown by the Aeroplan Member on regular scheduled flights operated by the airline partner. Mileage accrual is determined by the operating airline, unless otherwise specified. For codeshare flights, the booking class shown on the ticket may differ from the fare/booking class applicable for mileage accrual on the operating airline.
3. The Aeroplan Miles credited are calculated according to the routing on the ticket and the fare type purchased for each flown flight. On nonstop and direct flights, mileage credited will be calculated based upon the fare type and the distance from origin to final destination, regardless of the number of stops. On connecting flights that require a change of plane and flight number, mileage credited will be calculated based upon the fare type and the distance from origin to destination for each segment of the trip.
4. The Aeroplan Miles credited when using purchased or complimentary upgrades are based on the original fare type purchased.
https://www3.aeroplan.com/earn_miles...Partner=United